Search code examples
asp.netmaster-pages

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


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.


Solution

  • 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>