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";
}
Published Tuesday, July 10, 2007 7:15 PM by dwahlin
Filed under: ,

Comments

# re: Coping with Click-Happy AJAX Application Users

Tuesday, July 10, 2007 11:43 PM by Dave

You might be interested in my similar way of handling the same problem:  <a href="encosia.com/.../">CSS style as AJAX progress indicator</a>.

# re: Coping with Click-Happy AJAX Application Users

Wednesday, July 11, 2007 12:51 AM by dwahlin

Good stuff....thanks for commenting Dave.  For anyone else who may be interested, here's the direct link to the post Dave mentions.  There's quite a bit of AJAX-specific content on the blog.

encosia.com/.../css-style-as-ajax-progress-indicator

# 27 Links Today (2007-07-12)

Thursday, July 12, 2007 11:21 AM by 27 Links Today (2007-07-12)

Pingback from  27 Links Today (2007-07-12)