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?

有帮助吗?

解决方案

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>

其他提示

In your login Page get a reference to Master Page button control and then disable it.

 Button b = Master.FindControl("ButtonID");
 b.Enable= false;

To change default buton of master page change it's default button in master page codebehind

form1.DefaultButton = "New button ID";

oR  from login page codebehind

Form.DefaultButton = "New button ID";
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top