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.


Comments

Author: DotNet07 Feb 2012 Member Level: Silver   Points : 0

This is exactly what I need for few days ago. Thank you so much and hope more helpful topics from you.

Author: Manas08 Feb 2012 Member Level: Bronze   Points : 0

good question..

Guest Author: Nenad19 Feb 2012

The the same rules apply as berofe about hooking up the toolkit; there is no change but to use Asp.net one always needs a form tag to use the controls. Am I missing something?



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: