asp.netdefaultbutton

switch masterpage button default button property in ASP.NET


I'm developing an ASP.NET web app (C#, VS2010), I have a master page which has a button (search button) and a textbox, when I press enter, this search button executes, but I don't want this master page search button to work when I'm in my login page. In my login page I have two textboxes and another button (login button), I want this login button to work as default button (execute with enter key) when I'm in login page. Of course I've not used any javascript or DefaultButton property at all

how can I disable masterpage button enter key in my login page?


Solution

  • You need to define a DefaultButton around each area you want default buttons, it will then use the part of the form that has focus:

    <asp:Panel id="SearchPanel" runat="server" DefaultButton="Search" >
          <asp:Button id="Search" runat="server" Text="Search" />
    <asp:Panel>
    <asp:Panel id="LoginPanel" runat="server" DefaultButton="Login" >
          <asp:Button id="Login" runat="server" Text="Login" />
    <asp:Panel>