ASP.NET – jQuery is not Working after Postback

元气小坏坏 提交于 2019-12-12 03:37:26

问题


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
});

回答1:


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.



来源:https://stackoverflow.com/questions/39095879/asp-net-jquery-is-not-working-after-postback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!