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.
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 ...
Comments
Can we implement this feature for multiple nested UpdatePanels? If yes, could you please tell us how to achieve the same?