开发者

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.


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>


if you need to do it from code, use

Me.Form.DefaultButton = Me.btn.UniqueID

Where btn is your button control.


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>


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


Microsoft say:

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

enter link description here


$(document).ready(function(){
    document.getElementById("text_box_id")
    .addEventListener("keyup", function(event) {
    event.preventDefault();
    if (event.keyCode === 13) {
        document.getElementById("button_id").click();
    }
    });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜