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.

4
  • How did you use the panel? I am assuming you put the 2 buttons inside the panel. Commented Sep 14, 2016 at 2:26
  • @KeyurPATEL Panel1.DefaultButton = "ButtonTT"; Commented Sep 14, 2016 at 2:38
  • I'll put my suggestion in an answer since its easier to explain. Commented Sep 14, 2016 at 2:38
  • @KeyurPATEL alright,thx man. Commented Sep 14, 2016 at 2:39

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

but this 2 buttons in different place.not in same <asp:panel> tag
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.