views:

448

answers:

3

I have 3 buttons in a form. One of them is the submit button. How can I make it the default button to be clicked when I press the enter key. Is there a property for this?

+4  A: 

There is a property for the form: defaultbutton.

<form runat="server" defaultbutton="myButton">
...
</form>

It is first time implemented in ASP.NET 2.0.

Biri
+2  A: 

Or you can do it in code - Page_load:

Page.Form.DefaultButton = btnSearch.UniqueID;

Whenever you press enter the btnSerach control will be used as default.

Kb
+4  A: 

Another helpful tip is that you can set the default button on asp:panel's too.

qui
Thank you. Thank you. Thank you. It's been a horrific morning of debugging and now I'd like to have your children!
Iain M Norman
Sounds painful :)
qui
Wow, this saved me a ton of time. Thanks!
Matthew Doyle