ASP.NET AJAX: Canceling an async postback

Lately I have been working quite a bit with the UpdatePanelAnimationExtender control.  I have been using this control along with the animation framework to spice up my ASP.NET GridViews, DetailViews and Wizards by running a simple animation script before and after the control has been updated via an async postback (typically the animation disabled a button, faded out the control, and/or popped up a progress indicator) .  This has worked great for the past few months, but recently a new requirement came in from the field requesting for a way to cancel an async operation.  Being aware of the abortPostBack method the PageRequestManager, I figured (more like hoped) it would be pretty simple to implement this feature.  I added a 'Cancel' button to my progress indicator and wired the onclick handler to invoke the abortPostBack method.  

Live Demo | View Source 

Clicking cancel did abort the async postback however, because the OnUpdated animation only runs when the UpdatePanel is updated my indicator was never being hidden and it was appearing as if the application was hanging.  I did some research, but I couldn't find anyone complaining about this issue.  My first approach to solving this was to look-up the animation component and invoke the animation myself.  Similiar to the following:

    function abort(){
        var prm = Sys.WebForms.PageRequestManager.getInstance(); 
        if(prm get_isInAsyncPostBack()){
            //  abort the postback
            prm abortPostBack();
            //  get the reference to the animation for the gridview
            var animation = $find('animation');
            //  simulate stopping by replaying the animation
            animation._postBackPending = false;
            animation.get_OnUpdatingBehavior().quit();
            animation.get_OnUpdatedBehavior().play();
        }
    }

That worked, but only if I set the _postBackPending of the animation to false manually.  This didn't feel exactly right since this is a private field - but I could not find a bettwe way to implement this.  I would appreciate hearing back if anyone has found a better way to accomplish this ... 


TrackBack

TrackBack URL for this entry:
http://mattberseth.com/blog-mt/mt-tb.fcgi/35

Listed below are links to weblogs that reference ASP.NET AJAX: Canceling an async postback:

» August 2nd Links: ASP.NET AJAX and the ASP.NET AJAX Control Toolkit from ScottGu's Blog
Here is the latest in my semi-regular link-listing series . Today's links are all about ASP.NET AJAX [Read More]

» August 2nd Links: ASP.NET AJAX and the ASP.NET AJAX Control Toolkit from ASP.Net Resources
Here is the latest in my semi-regular link-listing series . Today's links are all about ASP.NET AJAX [Read More]

Comments


Posted by: Shashi Kumar Nagulakonda on August 25, 2008 02:43 AM

Can we implement this feature for multiple nested UpdatePanels? If yes, could you please tell us how to achieve the same?

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)