Coping with Click-Happy AJAX Application Users
Users can be impatient while waiting for data to be returned to a page (I'll admit I'm guilty of this occasionally). Fortunately, ASP.NET AJAX makes it easy to handle cases where impatient users continually click a refresh button (or other type of button) in an ASP.NET AJAX page causing extra load to be placed on your server.
Instead of allowing continuous requests to reach the server before their initial request has returned, you can easily let users know to kindly wait until their first request has returned and then cancel the subsequent request they've made. This can be done by using the PageRequestManager to handle the initializeRequest event. An example of performing this task is shown below. More details can be found in my latest .NET Insight article.
var prm = null;
function Init(sender)
{
prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm)
{
if (!prm.get_isInAsyncPostBack())
{
prm.add_initializeRequest(InitRequest);
}
}
}
function InitRequest(sender,args)
{
if (prm.get_isInAsyncPostBack() &&
args.get_postBackElement().id == 'btnRefresh') {
args.set_cancel(true);
if ($get("divChill").style.visibility != "visible")
{
$get("divChill").style.visibility = "visible";
setTimeout("ClearDiv()", 2000);
}
}
}
function ClearDiv()
{
$get("divChill").style.visibility = "hidden";
}