How to set default 'enter' on a specific button

ContentPage has a text box. When the user presses Enter in this text box, I try to launch the submit button on this ContentPage. I would like to disable this button event.

Instead, there is a search text box and a button at the top of the page from MasterPage, and this search button event fires.

How do I block this ContentPage submit button, and not the MasterPage search button?

I use Ektron CMS for content management.

+64
master-pages
Oct 03 '11 at 16:52
source share
4 answers

The easiest way is to place the fields and button inside the panel and set the default button to the button that you want to activate when you type.

<asp:Panel ID="p" runat="server" DefaultButton="myButton"> <%-- Text boxes here --%> <asp:Button ID="myButton" runat="server" /> </asp:Panel> 
+80
Oct 03 2018-11-11T00:
source share

if you need to do this from code use

 Me.Form.DefaultButton = Me.btn.UniqueID 

Where btn is your button control.

+29
Feb 14 '13 at 23:37
source share

You can use the DefaultButton property either on the form server or Panel . In your case, group the controls together in Panel , which should launch the same button:

 <asp:Panel ID="SearchBox" runat="server" DefaultButton="BtnSearch"> ... <asp:Button ID="BtnSearch" runat="server" Text="Search!" /> </asp:Panel> .... <asp:Panel ID="UserPanel" runat="server" DefaultButton="BtnUserSubmit"> ... <asp:Button ID="BtnUserSubmit" runat="server" Text="Submit" /> </asp:Panel> 
+14
03 Oct '11 at 16:55
source share

Now you can use the UseSubmitBehavior property to disable all the buttons that you do not want to launch when you click submit (see the documentation for more information)

  <asp:Button ID="BtnNotToFIre" runat="server" Text="Search" UseSubmitBehavior="false" /> 
+2
Jul 02 '17 at 12:43 on
source share



All Articles