简体   繁体   中英

jquery causes asp.net button to not click

I can't get the OnClick method for the button to fire

The button:

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

EDIT: postButton_Click is a code behind(server side) 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.

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. 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.

Solution which worked: https://stackoverflow.com/a/7673768/1753000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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