简体   繁体   English

jQuery导致asp.net按钮无法单击

[英]jquery causes asp.net button to not click

I can't get the OnClick method for the button to fire 我无法使用OnClick方法来触发按钮

The button: 按钮:

<asp:Button ID="postButton" runat="server" 
   Text="Create Thread" OnClick="postButton_Click" />

EDIT: postButton_Click is a code behind(server side) C# 编辑:postButton_Click是背后的代码(服务器端)C#

After a bit of trial and error i found out that the button does fire when the following line is removed: 经过一番尝试和错误后,我发现删除以下行时按钮会触发:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"  
   type="text/javascript"></script>

The scripts are loaded in this order: 脚本按以下顺序加载:

<link href="../ajax/jquery-ui-1.8.2.custom.css" 
   rel="stylesheet" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" 
   type="text/javascript"></script>
<script src="../ajax/jquery-ui-1.8.2.custom.min.js" 
   type="text/javascript"></script>

Changing the jQuery version does not help. 更改jQuery版本无济于事。

I have the exact same code on another page and it works fine. 我在另一页上有完全相同的代码,并且工作正常。 why does it happen and how can I fix it? 为什么会发生,如何解决?

EDIT: Codebehind (breakpoints set in this method fail to trigger) 编辑:代码隐藏(在此方法中设置的断点无法触发)

protected void postButton_Click(object sender, EventArgs e)
{
    Response.Redirect("test.aspx");
}

Ok so i finally found a fix for this problem 好的,所以我终于找到了解决此问题的方法

The reason that being that the ASP button was inside a JQuery UI dialog. 原因是ASP按钮位于JQuery UI对话框中。 When you use JQuery UI's Dialog plugin to bring up a div as a dialog, it usually pulls the div out of the form to do this and then ASP.Net elements don't work. 当您使用JQuery UI的Dialog插件调出div作为对话框时,通常会将div从表单中拉出以执行此操作,然后ASP.Net元素不起作用。

Solution which worked: https://stackoverflow.com/a/7673768/1753000 起作用的解决方案: https : //stackoverflow.com/a/7673768/1753000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM