Add a Progress Indicator to your asp page

Sometimes when developing a web application, you need to query a large amount of data, manipulate it and present it in a beautiful and readable way. That kind of operations – given that you created a resource optimized sql query – might take time and the user, waiting for data to appear on the screen, might get nervous not knowing what is really happening to the submitted request. So what? There are risks involved in that waiting: the user might hit other buttons sending multiple requests to the server. Again the user might submit data update more than one time. Or, simply, the user might think that your application is lousy and really slow (while you know that the user just submitted a very complicated query and you can’t do much about it in terms of speeding up the process!).
At that point, you probably need to put some sort of notice, making the user aware of the fact that the system is not freezing and that something is really going on: something like “Please wait. Data loading.”
I have done this many times and in different ways. Here I will explain how to do it with jQuery.
First of all, remember that doing this for all your documents might be time consuming, so think about using an include.

Ok lets start building the little popup message. Put the code everywhere in your .inc file:

Data loading. Please wait


As you can see, you have to assign an id and a class to the div tag. Inside the div tag you can put whatever you want. In the given example there’s a message and an animated gif like this:

 
Now, you can use a style for the progressIndicator div:
The way you make the popup look like, is up to you. Colours, borders, width, height and padding are easily configurable, but – as you may have noticed – the z-index, the position and display attributes are very important. That is because you need the popoup to be on top of everything else.

Now you need to make it work. Insert two functions: one to show the progressIndicator and one to hide it. First of all, include the jQuery library in the head of your document:
And then create the two functions:
Now that you have the two functions, you need to call them when needed. As an example you might want to call the opening function every time the user click an internal link. In order to do it you might use something like:
onClick="location.href= 'yourfile.asp';openProgressIndicator()"
And what about closing it? Well, you can close it using something like:

It is totally up to you, where and when to use the two functions, but – as you can see – it is very easy.
One of the important thing I would like to point out is that the “body onload” method might be quite tricky and might be a problem. Remember that you need to hide the progressIndicator when the page is completely loaded and when your data is actually displayed, not before. The onload trick sometimes doesn’t work as expected, so you might need to find another method to call the closeProgressIndicator function.
Isn't it easy? Enjoy!