Default Button for Enter Key on Web Form

  • Thread starter Thread starter Fred Nelson
  • Start date Start date
F

Fred Nelson

Hi:

I'm a relative newby and I'm writing a C# web application in VS2005.

I have several forms with multiple buttons. In 95% of the cases users
will click a particular button.

I would like to allow them to press the enter key if they are selecting
the "95% of the time" button.

I have tried the "AccessKey" property. If I set the value to "1" then
the button's click event is fired if the user presses ALT-1.

Is there a way to do this for the enter key?

Your help will be GREATLY appreciated!

Thanks,

Fred
 
Hey Folks:

Thanks for your help - it pointed me in the right direction!

I have found that it is very easy to insert lines in the page_load event
to define the default focus and the default button:

Page_Load(..)
{
Page.Form.DefaultButton = btnEnter.UniqueID;
Page.Form.DefaultFocus = tbxInputField.UniqueId;
}

It works perfectly AND it's only two lines of code!

Thanks for your help!

Fred
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top