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.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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" />

Method 2

if you need to do it from code, use

Me.Form.DefaultButton = Me.btn.UniqueID

Where btn is your button control.

Method 3

You can use the DefaultButton property on either a server-side form control or Panel control. In your case, group the controls together in a Panel that should fire off the same button:

<asp:Panel ID="SearchBox" runat="server" DefaultButton="BtnSearch">
    <asp:Button ID="BtnSearch" runat="server" Text="Search!" />
<asp:Panel ID="UserPanel" runat="server" DefaultButton="BtnUserSubmit">
    <asp:Button ID="BtnUserSubmit" runat="server" Text="Submit" />

Method 4

You can now use UseSubmitBehavior property to disable all the buttons you don’t want to fire when hitting submit (check out the documentation for more info)

    <asp:Button ID="BtnNotToFIre" runat="server" Text="Search" UseSubmitBehavior="false" />

Method 5

Microsoft say:

<form id="Form1"

enter link description here

Method 6

    .addEventListener("keyup", function(event) {
    if (event.keyCode === 13) {

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x