Setting the button triggered by the enter key
In ASP.Net 2.0, you can actually set the button that will be triggered in a form when the user presses the Enter key. This is a nice improvement over ASP.Net 1.1.
The HtmlForm control has a DefaultButton property which allows you to set which button is effectively clicked when the user hits Enter. This property is also available on the Panel control in cases where you want different buttons to be triggered when a user moves into different Panels on the page.
It's pretty easy to use this as this code example shows:
In this example, even though there are two other submit buttons declared before it in the form, btnNum3 will be the button that is pushed if the user hits Enter.
The HtmlForm control has a DefaultButton property which allows you to set which button is effectively clicked when the user hits Enter. This property is also available on the Panel control in cases where you want different buttons to be triggered when a user moves into different Panels on the page.
It's pretty easy to use this as this code example shows:
<form id="formId" DefaultButton="btnNum3" runat="server"> ... <input type="submit" name="btnNum1" id="btnNum1" value="Button 1" /> <input type="submit" name="btnNum2" id="btnNum1" value="Button 2" /> <input type="submit" name="btnNum3" id="btnNum1" value="Button 3" /> </form>
In this example, even though there are two other submit buttons declared before it in the form, btnNum3 will be the button that is pushed if the user hits Enter.
| Rating: | 100% positive, 1 Vote |
| Categories: | programming ASP .Net web |
| Added: | on Jun 05, 2007 at 6:09 pm |
| Added By: | an anonymous user |

