jquery + asp.net delay postback

爱⌒轻易说出口 提交于 2019-12-08 08:34:42

问题


I would like to implement a slideUp jQuery effect on LinkButton click and then do postback on page. The effect takes 600ms to accomplish. The problem I confront with is that before jQuery effect finishes page already does postback, so the jQuery script stops somewhere halfway. Is there any way to delay postback other then doing a manual postback?


回答1:


It is possible to provide a function to slideup which will only execute when the sliding is done:

formDiv.slideUp('normal', function () {
    $(form).submit();
  });



回答2:


You can put the call to load/reload the page in the callback function of the slideUp animation.

Something like:

$("#myElement").click(function() {
    $("#otherElement").slideUp(600, function() {
        // $("#form").submit(); // or
        // window.location.assign("mypage.aspx");
    });
})

If you could post your code I can show you in more detail.




回答3:


You can block the PostBack event with return false. Then invoke the PostBack of the button manually by calling __doPostBack with the correct LinkButton name by using it's UniqueID.

<script type="text/javascript">
    function myFunction() {
        //do stuff
        setTimeout(function () { delayedPostBack(); }, 1000);
    }

    function delayedPostBack() {
        __doPostBack('<%= LinkButton1.UniqueID %>', '');
    }
</script>

<asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="myFunction(); return false;" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>


来源:https://stackoverflow.com/questions/8397545/jquery-asp-net-delay-postback

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