By default, when a page generates multiple asynchronous postbacks at the same time, the most recently generated postback takes precedence. In some cases, you can give priority to a specific asynchronous postback and cancel other postbacks.
Prerequisite
To implement these procedures in your own development environment, you need to:
Microsoft Visual Studio 2005 or Microsoft Visual Web Developer Express Edition.
An AJAX-enabled ASP.net web site.
Create a script to give priority to a particular postback element
First, create ECMAScript (JavaScript) code to manage asynchronous postbacks in the browser.
Create a script to give priority to a particular postback element
In the ASP.net web site, add a JScript file and name it postbackprecedence.js.
Add the following script to the file:
Sys.Application.add_load (Applicationloadhandler)
function Applicationloadhandler (sender, args)
{
if (! Sys.WebForms.PageRequestManager.getInstance (). Get_isinasyncpostback ())
{
Sys.WebForms.PageRequestManager.getInstance (). Add_initializerequest (initializerequest);
}
}
var Divelem = ' AlertDiv ';
var Messageelem = ' alertmessage ';
var exclusivepostbackelement = ' Button1 ';
var lastpostbackelement;
function initializerequest (sender, args)
{
var PRM = Sys.WebForms.PageRequestManager.getInstance ();
if (Prm.get_isinasyncpostback () &&
Args.get_postbackelement (). id = = exclusivepostbackelement)
{
if (lastpostbackelement = = exclusivepostbackelement)
{
Args.set_cancel (TRUE);
ActivateAlertDiv (' Visible ', ' A previous postback is still executing. The new postback has been canceled. ');
settimeout ("ActivateAlertDiv" (' Hidden ', ') ', 1500);
}
else if (lastpostbackelement!== exclusivepostbackelement)
{
Prm.abortpostback ();
}
}
else if (Prm.get_isinasyncpostback () &&
Args.get_postbackelement (). ID!== exclusivepostbackelement)
{
if (lastpostbackelement = = exclusivepostbackelement)
{
Args.set_cancel (TRUE);
ActivateAlertDiv (' Visible ', ' A previous postback is still executing. The new postback has been canceled. ');
settimeout ("ActivateAlertDiv" (' Hidden ', ') ', 1500);
}
}
Lastpostbackelement = Args.get_postbackelement (). ID;
}
function ActivateAlertDiv (visstring, msg)
{
var adiv = $get (Divelem);
var Aspan = $get (Messageelem);
adiv.style.visibility = visstring;
aspan.innerhtml = msg;
}
if (typeof (Sys)!== "undefined") Sys.Application.notifyScriptLoaded ();