Hi,
If you want to have multiple default buttons (for example you have a search-button and a contact form on the same page), you could use it this way:
<form runat="server">
<asp:Panel runat="server" DefaultButton="btnSearch">
<asp:TextBox ID="tbSearchText" runat="server" />
<asp:Button ID="btnSearch" runat="server" Text="Search" />
</asp:Panel>
<asp:Panel runat="server" DefaultButton="btnSendContact">
<asp:TextBox ID="tbFirstname" runat="server" />
<asp:TextBox ID="tbLastname" runat="server" />
<asp:TextBox ID="tbComment" runat="server" />
<asp:Button ID="btnSendContact" runat="server" Text="Submit" />
</asp:Panel>
</form>
Using a panel around some server-controls renders a
div
HTML tag and adds some
JavaScript
which allows the default-button firing.
If you ask yourself why you have to use this, thats simple: because ASP.NET only allows one
form
HTML tag, you cannot create multiple forms on one page, so you cannot use the HTML feature of the default button firing on each form (because the browser would just fire the first button it finds on the page).
Hope this helps.
Best regards and happy coding,
Chris