简体   繁体   中英

jquery + asp.net delay postback

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?

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

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.

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