Things I Learned Today in .NET - defaultbutton in ASP.NET 2.0
I have been doing a lot of web programming lately as I have been trying to develop a front end for Morale. This is the first time I have done any programming in ASP.NET 2.0 for things that are going to be consumed by the public. I have been mostly been programming .NET 2.0 using Windows Forms....Anyway, I wanted to do one of the most common things that web programmers want to do. That is have a default button that is clicked when the user fills out a form and presses enter on the keyboard. So I started doing this "the old way" by coding up some javascript. You know the code by know:
onkeydown="if event.key == 13.........". I found that there is now a very easy way to do this in .NET 2.0. That is add the attribute defaultbutton="<ControlID>" to the form tag on your form. This adds the following code to your form:
onkeypress="javascript:return WebForm_FireDefaultButton(event, '<ControlID>')"
This calls a new ASP.NET 2.0 client side library. Easy sh*&%.