Wednesday, May 20, 2009

multiple submit buttons and the enter key

As you know it is the limitation of asp.net that it has only one form, so if you have another section which needs enter key submission, than you can use default button as used below.
The defaultButton property of Panel or Form is used to ensure Enter Key Submission. Typically people used to Enter Key submission and if it is disabled, it might be annoying certain times.

The defaultButton really provides a way to handle Enter Keys for respective portions of the page when the focus is there.

Example:

<form defaultbutton="button1" runat="server">
<asp:textbox id="textbox1" runat="server"/>
<asp:textbox id="textbox2" runat="server"/>
<asp:button id="button1" text="Button1" runat="server"/>

<asp:panel defaultbutton="button2" runat="server">
<asp:textbox id="textbox3" runat="server"/>
<asp:button id="button2" runat="server"/>
</asp:panel>
</form>

1 comment:

Vibe said...

Nice, the pannel thing worked. Had 3 user controls in one page.