« AJAX Rain | Main | Tracing in ASP.NET Application Classes »

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.

Sys.Application.add_init(Init);
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";
}
Posted on Tuesday, July 10, 2007 at 07:33PM by Registered CommenterDan Wahlin in | CommentsPost a Comment

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.
Editor Permission Required
You must have editing permission for this entry in order to post comments.