简体   繁体   中英

ASP.NET – jQuery is not Working after Postback

Function works one time only but fails when page loads after Postback . Am I missing something with onclick method?

My HTML:

        <!-- Iframe Section -->
        <div class="rmpView" id="ContentPlaceHolder1">
            <iframe src="/Tabs/tabOne.aspx?ID=0" height="500" width="100%">

                <html>
                    <head></head>
                    <body>
                        <div id="wrapper-iframe">
                            <label>Name:</label>
                            <input type="text"/>
                            <a href="javascript:void(0)" data-target="dBoxPopup" class="btn">Open Popup</a>
                        </div>
                    </body>
                </html>

            </iframe>
        </div>
        <!-- Iframe Section ENDS -->

        <!-- Popup body -->
        <div id="dBoxPopup" class="dialog-box">
            <uc1:wucPopupContent runat="server" ID="wucPopupContent" />
        </div>
        <!-- Popup body ENDS -->

My jQuery:

$("#ContentPlaceHolder1 iframe").load(function (e) {
    // trigger popup onclick inside the iframe BEGINS
    $(this).contents().find('.btn').on("click", function () {
        var btnHref = $(this).attr("data-target");
        javascript: popup(btnHref)
    });
    // trigger popup onclick inside the iframe ENDS
});

One reason could be that after the post back, the button is not able to be found. If this is the case, the popup will not be invoked since the button itself is not present.

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