How to give more than one default button in the web page?
This explains how to use more than one default button in the web page. Form and panel have DefaultButton property, so we can give more than one default button in the web page by providing the different default button for the panels. Learn how to give more than one default button in the web page?
Know more about how to give more than one default button in the web page?
Assume we have the form with the operations Login and Search. When we press the 'Enter' key after entering login id and password, the Search operation will be executed as default. This is not as expected.
This problem is resolved by setting the DefaultButton property for the Panels. We have to create two panels, one with login form and another with search form.
If we press the 'Enter' key after entering login id and password, the 'Login' button should be hit ie. the Login button should be act as the default button.
If we press the 'Enter' key after entering search keyword, the 'Search' button should be hit ie. the Search button should be act as the default button in this case.
Example:
<asp:Panel ID="panelSearch" runat="server" DefaultButton="buttonSearch">
Enter Keyword:
<asp:TextBox ID="textKeyword" runat="server"></asp:TextBox>
<asp:Button ID="buttonSearch" runat="server" Text="Search"
onclick="buttonSearch_Click" />
</asp:Panel>
<asp:Panel ID="panelLogin" runat="server" DefaultButton="buttonLogin" >
Enter Username:
<asp:TextBox ID="textUserName" runat="server"></asp:TextBox>
Enter Password:
<asp:TextBox ID="textPassword" runat="server" TextMode="Password">
</asp:TextBox>
<asp:Button ID="buttonLogin" runat="server" Text="Login"
onclick="buttonLogin_Click" />
</asp:Panel>
Now when we press the 'Enter' key after entering login id, password and search keyword, then the first panel default button should be act as default button for the form.
This is exactly what I need for few days ago. Thank you so much and hope more helpful topics from you.