You can implement asynchronous postbacks in ASP.net by using the NET UpdatePanel Web server control on the page. The UpdatePanel control no longer needs to refresh the entire page on each postback, which improves the user experience. In the browser, the Sys.WebForms.PageRequestManager class in the Microsoft AJAX Library manages events for asynchronous postbacks in the client page life cycle. You can customize the way that asynchronous postbacks occur by handling events exposed by the PageRequestManager class.
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 that cancels the postback
First, create ECMAScript (JavaScript) code to manage asynchronous postbacks in the browser.
Create JavaScript code to cancel postback
In the ASP.net web site, add a new JScript file and name it cancelpostback.js.
Add the following script to the file:
var Divelem = ' AlertDiv ';
var Messageelem = ' alertmessage ';
Sys.Application.add_load (Applicationloadhandler)
function Applicationloadhandler (sender, args)
{
Sys.WebForms.PageRequestManager.getInstance (). Add_initializerequest (CheckStatus);
}
function CheckStatus (sender, args)
{
var PRM = Sys.WebForms.PageRequestManager.getInstance ();
if (Prm.get_isinasyncpostback () & Args.get_postbackelement (). id = = ' CancelRefresh ') {
Prm.abortpostback ();
}
else if (Prm.get_isinasyncpostback () & Args.get_postbackelement (). id = = ' Refreshbutton ') {
Args.set_cancel (TRUE);
ActivateAlertDiv (' Visible ', ' still working on previous request. ');
}
else if (!prm.get_isinasyncpostback () & Args.get_postbackelement (). id = = ' Refreshbutton ') {
ActivateAlertDiv (' Visible ', ' retrieving headlines. ');
}
}
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 ();