R – ASP.NET default button

asp.netmaster-pages

I have a master page with a search box and button at the top. This search functionality is taking over the "enter" key for all my web forms that use this master page. That is, if I have a login page that uses this master page and the user enters in their username/password and hits "enter", instead of logging in the user the system performs a search.

What's the best way to set up the default submit buttons. I could wrap everything in asp Panels and set the DefaultButton property, but that seems a bit tedious. Is there a better way?

Best Answer

use defaultbutton property of form or panel

<form defaultbutton=“button1” runat=“server”>    
    <asp:button id=“button1” text=“Same Page” runat=“server”/>    
    <asp:panel defaultbutton=“button2” runat=“server”>    
       <asp:textbox id=“foo” runat=“server”/>    
       <asp:button id=“button2” runat=“server”/>    
    </asp:panel>    
</form>
Related Topic