0

I have 2 buttons in my webpage.When i press "Enter",it auto perform "close_topic",but i want my enter button to perform "button_click".

 <asp:Button ID="btnLogout" Text="Close Topic" OnClick="close_topic" runat="server" />

 <asp:Button ID="ButtonTT" Text="Click" runat="server" OnClick="button_click" />

protected void button_Click(object sender, EventArgs e)
{

}

protected void close_topic(object sender, EventArgs e)
{

}

tried to use <asp:Panel ID="Panel1" runat="server" DefaultButton="ButtonTT">,but not working.

KyLim
  • 468
  • 1
  • 6
  • 22

1 Answers1

1

Did you wrap your panel around the 2 buttons? As follows:

<asp:Panel ID="Panel1" runat="server" DefaultButton="ButtonTT">
    <asp:Button ID="btnLogout" Text="Close Topic" OnClick="close_topic" runat="server" />
    <asp:Button ID="ButtonTT" Text="Click" runat="server" OnClick="button_click" />
</asp:Panel>

Edit

Based on how to set a default 'enter' on a certain button, you can do it using code also:

Me.Form.DefaultButton = Me.btn.UniqueID;

or

Me.Page.Form.DefaultButton = = Me.btn.UniqueID;

Replacing the Me.Page with whatever your page name is.

Community
  • 1
  • 1
Keyur PATEL
  • 2,299
  • 1
  • 15
  • 41
  • but this 2 buttons in different place.not in same tag – KyLim Sep 14 '16 at 02:44
  • Would it be too difficult to wrap your whole page in the panel? Or just the part containing the 2 buttons, as long as you put a panel around the 2 buttons and set DefaultButton action, it will choose the right one. – Keyur PATEL Sep 14 '16 at 02:50