0

I have Logout button in master page in my website.

Now i had made a content page belonging to master page, in that i have 1 textbox and 1 button. In this page i have done coding of search on a button click of a value written in textbox. but when i enter some text in a textbox and just make enter click it calls the logout button which is in master page.

I just want that when i write some text in textbox and press enter, it should call a button where the search coding is done.

4

2 回答 2

1

如果你使用的是普通的 ASP.NET,你可以用一个面板包围你的文本框和按钮。在该面板上,您可以设置属性“DefaultButton”。当尝试通过 Enter 键提交表单时,此面板中的每个控件都会触发该 DefaultButton。

<asp:Panel runat="server" DefaultButton="btnSearch">
    <asp:TextBox runat="server" ID="txtSearch" Text="" />
    <asp:Button runat="server" ID="btnSearch" Text="Search" />
</asp:Panel>
于 2013-06-25T09:45:17.370 回答
0

您必须使用默认面板。试试这个,希望对你有帮助

 <div id="search">
    <asp:Panel ID="defaultpanel" runat="server">
      <asp:TextBox ID="txtSearch"  runat="server" Text=""></asp:TextBox>
  <asp:Button ID="btnSearch" runat="server" Text="Go"  OnClick="btnSearch_Click"
                                TabIndex="0" />
        </asp:Panel>

并将脚本添加为

<script type="text/javascript">
            $('[id*=txtSearch]').keydown(function (e) {
    var code = e.keyCode || e.which;
    //alert("jj");
    if (code === 13)
    {
        e.preventDefault(); 
        $("[id*=btnSearch]").trigger('click');
    }         
});
        </script>
于 2013-06-25T09:46:26.953 回答