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

后端 未结 6 1862
萌比男神i
萌比男神i 2020-12-01 11:47

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 part

相关标签:
6条回答
  • 2020-12-01 12:01

    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>
    ....
    <asp:Panel ID="UserPanel" runat="server" DefaultButton="BtnUserSubmit">
        ...
        <asp:Button ID="BtnUserSubmit" runat="server" Text="Submit" />
    </asp:Panel>
    
    0 讨论(0)
  • 2020-12-01 12:04

    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" />
    
    0 讨论(0)
  • 2020-12-01 12:09

    if you need to do it from code, use

    Me.Form.DefaultButton = Me.btn.UniqueID
    

    Where btn is your button control.

    0 讨论(0)
  • 2020-12-01 12:12

    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>
    
    0 讨论(0)
  • 2020-12-01 12:15

    Microsoft say:

    <form id="Form1"
        defaultbutton="SubmitButton"
        defaultfocus="TextBox1"
        runat="server">
    

    enter link description here

    0 讨论(0)
  • 2020-12-01 12:21
    $(document).ready(function(){
        document.getElementById("text_box_id")
        .addEventListener("keyup", function(event) {
        event.preventDefault();
        if (event.keyCode === 13) {
            document.getElementById("button_id").click();
        }
        });
    });
    
    0 讨论(0)
提交回复
热议问题