Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在仍然允许javascript运行的情况下,如何防止回发?_C#_Asp.net - Fatal编程技术网

C# 在仍然允许javascript运行的情况下,如何防止回发?

C# 在仍然允许javascript运行的情况下,如何防止回发?,c#,asp.net,C#,Asp.net,此Asp.Net页面的一部分包含以下内容: <asp:Panel runat="server" DefaultButton="get"> Enter Employee Name or Click Search to Return All: <asp:TextBox runat="server" ID="participant" ></asp:TextBox> <asp:Button runat="server" ID="get"

此Asp.Net页面的一部分包含以下内容:

<asp:Panel runat="server" DefaultButton="get">
    Enter Employee Name or Click Search to Return All:
    <asp:TextBox runat="server" ID="participant" ></asp:TextBox>
    <asp:Button runat="server" ID="get" UseSubmitBehavior="false" Text="Search" />
</asp:Panel>

我如何解决这个问题,使enter键不会导致回发,但仍然触发JS?

我通过添加一个额外的默认值解决了这个问题


尝试返回false而不是preventDefaultAdd OnClientClick=return false;在ASP:Button控件上。看起来是这样的:这有很多建议:你确定这个javascript被调用了吗?查看您的代码时,此代码$get可能必须是$@anwyatt。。。为什么它是服务器端的按钮呢?只要让它成为一个普通的html按钮,你就会没事的。
$(document).ready(function () {
            $("#get").click(function (e) {
                e.preventDefault();
                document.getElementById('<%= userTable.ClientID %>').style.display = "block";
                getUserNames();
            });
            $("#content_contentPlaceHolder_participant").keypress(function (event) {
                if (event.keyCode == 13) {
                    $("#get").click();
                }
            });
        });
participant.Attributes.Add("onkeydown", "return (event.keyCode!=13);");
$(document).ready(function () {
        $("#get").click(function (e) {
            e.preventDefault();
            document.getElementById('<%= userTable.ClientID %>').style.display = "block";
            getUserNames();
        });
        $("#content_contentPlaceHolder_participant").keypress(function (event) {
            if (event.keyCode == 13) {
                event.preventDefault(); // <-- added this line
                $("#get").click();
            }
        });
});