Wednesday, April 26, 2006 1:14:07 PM UTC :: Filed Under ASP.NET

It seems like such a simple thing.  You have a form.  You have one submit button.  Yet when you hit your Enter key, the form submits, the page posts back, and… well, nothing.  For some reason Internet Explorer doesn’t seem to understand that the Enter key should post the form.

Thanks to some handy-work by the ASP.NET 2.0 developers, there is a solution for this.  In your <form> tag, you now have a property called defaultbutton that can be used to make sure that the button you want to be ‘clicked’ when hitting the enter key actually is.

<form id="form1"  runat="server" defaultbutton="btnSearch">

But wait, there is more!  A new defaultbutton property also makes it super easy to make sure that the cursor auto-magically starts on the field of your choosing so you don’t have to write your own onload JavaScript event handler:

<form id="form1"  runat="server" defaultbutton="btnSearch" defaultfocus="txtSearch">

The more I learn about ASP.NET 2.0 and Visual Studio .NET 2005, the more I’m impressed.  It’s the little details like these that get me all excited!

Comments are closed.
Navigation
On this page....
Search
Archives
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Categories
Contact me
Send mail to the author(s) Contact Todd M. Taylor