简体   繁体   English

jquery + asp.net延迟回发

[英]jquery + asp.net delay postback

I would like to implement a slideUp jQuery effect on LinkButton click and then do postback on page. 我想在LinkBut​​ton上实现一个slideUp jQuery效果,然后在页面上进行回发。 The effect takes 600ms to accomplish. 效果需要600ms才能完成。 The problem I confront with is that before jQuery effect finishes page already does postback, so the jQuery script stops somewhere halfway. 我遇到的问题是,在jQuery效果完成页面之前已经回发了,所以jQuery脚本在中途停止了。 Is there any way to delay postback other then doing a manual postback? 有没有办法延迟回发,然后进行手动回发?

It is possible to provide a function to slideup which will only execute when the sliding is done: 可以提供一个仅在滑动完成时执行的滑动功能:

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

You can block the PostBack event with return false . 您可以使用return false阻止PostBack事件。 Then invoke the PostBack of the button manually by calling __doPostBack with the correct LinkButton name by using it's UniqueID . 然后通过使用它的UniqueID调用具有正确LinkBut​​ton名称的__doPostBack手动调用按钮的PostBack。

<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>

You can put the call to load/reload the page in the callback function of the slideUp animation. 您可以在slideUp动画的回调函数中调用加载/重新加载页面。

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. 如果您可以发布代码,则可以向您详细介绍。

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

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