Rob Chartier ~ Contemplation...

.NET, C#, Work, etc.

News






www.flickr.com
This is a Flickr badge showing public photos from Rob & Kat Chartier. Make your own badge here.


Even Quicker Links

Javascript Status Bar sample (Useful for Ajax)...

This is my first post regarding Ajax.  What I did was created a few lines of code in Javascript and HTML which allows you to essentially have a StatusBar like display for your Ajax calls.  Useful for those longer-running calls.

Here is the setup:

var done=false; var dispObject; var StatusBarPrefixText='Calculating Please Wait'; function timeout(counter){ if(!done) { dispObject.innerHTML = dispObject.innerHTML+ '.'; if(counter==7) { dispObject.innerHTML = StatusBarPrefixText; counter=-1; } counter++; window.setTimeout('timeout('+counter+')', counter*100); } } function InitStatusBar() { done=false; dispObject=document.getElementById("StatusBar"); dispObject.innerHTML = StatusBarPrefixText; }
 

To integrate this with your Ajax calls you only need to do three things:

   1. Before calling your actual Ajax method, call: InitStatusBar();

    2. After calling your Ajax method, call: timeout(0);

For example:

If you had:

<INPUT onclick="SiteMethods.ServerSideAdd(1, 2, ServerSideResult_CallBack);" type="button" value="Add">

Now changes too:

<INPUT onclick="InitStatusBar(); SiteMethods.ServerSideAdd(1, 2, ServerSideResult_CallBack); timeout(0);" type="button" value="Add">

   3. And finally place your status bar object anywhere on the page:

<SPAN id="StatusBar"> </SPAN>

Posted: Aug 15 2005, 01:26 PM by Rob Chartier | with 2 comment(s)
Filed under:

Comments

Dave Tigweld said:

Haven't tried your example but its definitely something someone using ajax would need. I typically use mouse capture and change the status of the cursor to an hourglass as well.
# August 15, 2005 9:41 PM

Anatoly said:

Few thoughts
1) You can create div at run-time on client inside InitStatusBar()
2) I think timeout(0) call must be maid from ServerSideResult_Callback function and not after ServerSide call.
3) Definitely useful thing
# August 16, 2005 3:00 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)