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!

Share This Article With Your Friends!

Googles Ads Facebook Pixel Bing Pixel LinkedIn Pixel