how to set a default 'enter' on a certain button

Ron picture Ron · Oct 3, 2011 · Viewed 94.4k times · Source

There is a textbox on a ContentPage. When the user presses Enter in that textbox I am trying to fire a 'Submit' button on this ContentPage. I'd like to fire off that particular button's event.

Instead, there is a search textbox & button on the top of the page from a MasterPage, and this search button's event fires off.

How do I control to fire off this ContentPage's submit button, instead of the MasterPage's search button?

I am using Ektron CMS for my content management.

Answer

Kirk picture Kirk · Oct 3, 2011

The easiest way is to put the fields and button inside of a Panel and set the default button to the button you want to be activated on enter.

<asp:Panel ID="p" runat="server" DefaultButton="myButton">
  <%-- Text boxes here --%>
  <asp:Button ID="myButton" runat="server" />
</asp:Panel>