jQuery logic firing twice from a Usercontrol when used in a jQueryUI modal dialog

Posted by AaronS on Stack Overflow See other posts from Stack Overflow or by AaronS
Published on 2012-11-18T04:36:39Z Indexed on 2012/11/18 5:00 UTC
Read the original article Hit count: 178

Filed under:
|
|
|

I have an asp.net usercontrol that I'm using to put a bunch of HTML and Jquery logic into to be shared on several pages. This usercontrol has some dropdown boxes loaded from json calls and has no added codebehind logic.

When I use this usercontrol on a normal page it works perfectly fine, and no issues at all.

However, when I wrap the usercontrol in a div, and use a jqueryUI modal dialog, everything in the usercontrol fires twice. Not only code in the initial $(document).ready(function() {});, but also every function is also fired twice when called.

Debugging this in Visual Studio, I see that everything is first being called from the external JS file, and then again from a "script block" file that is somehow getting generated on the fly.

This script block file isn't getting generated on a page that doesn't wrap the user control in a modal.

The same happens if I use IISExpress or IIS7.

The question is, why is this script block file getting created, and why is all my jQuery logic firing twice?

--edit--

Here is the div:

  <div id="divMyDiv" title="MyDiv">
     <uc1:MyUserControl runat="server" ID="MyUsercontrol" />
</div>

Here is the modal logic that uses it:

        $("#divMyDiv").dialog({
            autoOpen: false,
            height: 400,
            width: 400,
            modal: true,
            open: function (type, data) {
                $(this).parent().appendTo("form");
            }
        });

Note: The problm still occurs, even if I remove the "open:" function. But, it does not occur if I remove the entire dialog block, so it is specific to this dialog call.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about ASP.NET