ts0

ts0

thoroughly scientific

follow me on Twitter!

Default button in ASP.NET

I just had to share this little tip with you. A really annoying problem in ASP.NET 1.1 caused by the fact WebForms are just one big HTML form, is that when you hit enter you never really know what's going to happen, and it's rarely what you wanted. For example, you have a search box and a search button, the search method is attached to the click event of the button. User comes a long, types his query, hits enter, the browser then posts back the form, but hasn't triggered any button clicks. In old multiformed applications you'd have a seperate form for the search control, and the browser would have triggered a click action on the single button in that form (the search button).

Thankfully ASP.NET 2 has a solution for this, you can surround your control in an asp:panel and set a button in it as the default button, then if the user hits enter while focus is on any control in that panel, that button is triggered.

Scott Guthrie has an article on it here.

Labels:

1 Comment - Post a comment

Adrian

Wow
thanks thats a big help, I've been wondering for some time how you can set that.

The thing I love about ASP.net is it has so many hurrends of hidden sercerts it just doesn't want you to know about.
ts0

<< Back to home page


Friends



Find Me (and my Social Graph)



RSS Feed

Archives 08.06 09.06 10.06 11.06 12.06 01.07 02.07 03.07



Thomas Shannon-Smith
Tom Shannon-Smith
Tom Shannon
Thom Shannon-Smith