简体   繁体   English

异步回发后jQuery无法正常工作

[英]jquery not working after async postback

i am doing async postback using updatepanel. 我正在使用updatepanel做异步回发。 after async postback jQuery functionality not working.I'm using jQuery to wire up some mousedown mouseenter effects on html table cells that are inside an UpdatePanel. 在异步回发jQuery功能无法正常工作之后。我使用jQuery在UpdatePanel内的html表格单元上连接了mousedown mouseenter效果。 The events are bound in $(document).ready 这些事件绑定在$(document).ready中

     <script type="text/javascript">

                $(function ()



     {
    $(".csstablelisttd").mousedown(function (e)
                        {
    //mouse down code
    });
 $(".csstablelisttd").mouseenter(function (e)
                        {
    //mouse entercode
    });
                        $("#contentPlaceHolderMain_btnFix").click(function (e)
                        {alert("Alert");//here alert is generate two times an then postback occurs
                           //btn click code
                        }
                    }

            </script>

    <asp:UpdatePanel ID="updatePanelTableAppointment" runat="server">
                            <ContentTemplate>
         <table id="table" runat="server">
             //table data
            </table>

                        </ContentTemplate><Triggers>
                            <asp:AsyncPostBackTrigger ControlID="btnFix" EventName="Click" />
                        </Triggers>
                    </asp:UpdatePanel>

asp:UpdatePanel replaces the content with the result returned from the server. asp:UpdatePanel用服务器返回的结果替换内容。 This means all hooked events previously will not work after a post back. 这意味着以前的所有挂接事件在回发后将无法使用。

Use jQuery.on() instead. 使用jQuery.on()代替。

For example: 例如:

<script type="text/javascript">
$(function () {

    $("#table").on("mousedown mouseenter", ".csstablelisttd", function (e) {
        //mouse down AND mouse enter code
    });

    $("#contentPlaceHolderMain_btnFix").on("click", function (e) {
        alert("Alert");//here alert is generate two times an then postback occurs
        //btn click code
    });
});
</script>

Note: if your mouse down and mouse enter code are different, split them out. 注意:如果您的鼠标向下和鼠标输入代码不同,请将它们分开。

Do the same for every event hook you include that will exist within the UpdatePanel . 对包含在UpdatePanel每个事件挂钩执行相同的操作。

You will have to add event handler for ajax endRequest provided by Toolkit. 您将必须为Toolkit提供的ajax endRequest添加事件处理程序。 Read more over here 这里阅读更多

Add In Javascript block that executes on page load. 在页面加载时执行的Add In Javascript块。

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle);

function endRequestHandle(sender, Args)
{
     alert("After ajax call");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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