Unknown Coder
Unknown Coder

Reputation: 6731

jQuery with C# doesn't fire onclick event

I have an ASP.NET application that also uses jQuery for modal pop-ups. If I put an ASP button (or image button) within the DIV for the jQuery modal, the "OnClick" event does not fire.

How can I fix this?

Upvotes: 1

Views: 710

Answers (2)

Marko
Marko

Reputation: 72222

By default, jQuery places the modal OUTSIDE of the asp.net <form> element.

You can easily append it to the form like:

$("#your-modal").parent().appendTo("form:first");

And this should fix your problems. It's a common problem with jQuery/ASP.NET.

Enjoy

Upvotes: 1

Nick Craver
Nick Craver

Reputation: 630379

When you create the dialog, you need to move it a bit for ASP.Net, like this:

$(".class").dialog({ 
  //options
}).parent().appendTo("form");

By default the .dialog() moves the content to just before </body> which most importantly is outside the <form></form>, so elements within it won't be included in the POST (or GET) to the server. If you manually move it like I have above, it'll resolve this issue.

Upvotes: 4

Related Questions