ASP.Net 1.0
For ASP.Net you can do something like this. But for ASP.Net 2.0 there are simplier ways to accomplish the same activity.
When someone presses enter on a certain button - do you want it to do a certain thing?
Here’s what to do…
Put this into your page design.
1 | <script language="javascript"> |
Add a button to your form, and hook up the logic that should be executed when someone presses the enter button. (In my example I created a button named btnQuickFind )
Add a onKeyDown element to the controls you want to add the behavior. For example
1 | <asp:textbox id="txtFinder" runat="server" AutoPostBack="True" |
Now… if the person presses the enter box while focus is in that control - a simulated btnQuickFind keyclick will be activated.
To Turn off the Enter button you can do the following
1 | <head> |
ASP.Net 2.0
ASP.NET 2.0 introduced a concept of a “default button”. The defaultbutton attribute can be used with
Here is sample HTML code that contains one form and one panel control:
1 | <form defaultbutton="button1" runat="server"> |
On any field in the form, if you press Enter, it would do the same thing as pressing the ‘Button 1’ button. The exception is the controls inside the Panel. If you press the Enter button on textbox3, then it would have the same effect as executing the function associated with ‘Button 2’.