Welcome to Professional ASP.NET - Chris Love's Official Blog Sign in | Join | Help

Chris Love's Official ASP.NET Blog

Chris Love's Helpful tips, tricks and pragmatic development knowledge for the ASP.NET world.
Add to Technorati Favorites


ASP Insider Follow Me On Twitter
Setting the Default Button and the Control Tab Order

This is more applicable to ASP.NET 1.1, but can be used in 2.0 anyway.  One of the top complaints I get from clients is the abiltiy to enter information in a form and just hit the enter key and the form post back.  In ASP.NET this just cuases the form to post back and nothing get processed.  Sort of lame, but there is a way to make this work.

I put this in the PageLoad login, buy this will set the default button to be clicked when the user hits the Enter key.

Page.RegisterHiddenField("_EVENTTARGET", "btnMyDefaultButton")

Of course 'btnMyDefaultButton' is the Id you set for the button you want to be processed.  ASP.NET 2.0 now has the DefaultButton property on the Form object.

Another feature you should be aware of is setting the order in which users can tab through the fields in a form.  Each control has an attribute, TabIndex.  You will want to set the numerical order that tabbing will occur with this attribute.

Hope this helps you make better user forms!

Posted: Monday, August 28, 2006 5:19 PM

by Chris Love
Filed under: ,

Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS