Today I was tasked with creating a simple wait page that could be used throughout our web application. This is very simple and can be quite robust with some simple Java scripting. However, here comes the bombshell, we have clients that are using Windows 95 so anything that is implemented in java script has to have an alternative. So I thought for awhile, I figured that the clients that where using Windows 95 would be used to waiting so showing them a waiting page was not very important to me. So here is the solution I came up with.
If you take a look at the response object there is an interesting method, Flush(), this method sends all the currently buffered content to the client. So at the beginning of an operation that will take awhile I can write some simple html to the response and send it to the client. Here is how I choose to implement it.
public static class load
{
public static void ShowLoad(string p_imgSrc, System.Web.HttpResponse Response)
{
Response.Write("<div id=\"divWaiting\" style=\"Display:none;\">");
Response.Write("<img src=\""+p_imgSrc+"\" />");
Response.Write("</div>");
Response.Write("<script language=javascript>");
Response.Write("function Start_Wait()");
Response.Write("{");
Response.Write("document.getElementById(\"divWaiting\").style.display = \"block\";");
Response.Write("}");
Response.Write("function Stop_Wait()");
Response.Write("{ ");
Response.Write("document.getElementById(\"divWaiting\").style.display = \"none\";");
Response.Write("}");
Response.Write("Start_Wait();");
Response.Write("</script>");
Response.Flush();
}
}
With this simple helper class there are two things that you have to do to implement the wait page. First, at the top of you HTML page put a script tag that calls the stop_Wait function.
<script language="javascript" type="text/javascript">Stop_Wait();</script>
Second, in the server side code at the beginning of a lengthy operation make a call to ShowLoad.
load.ShowLoad("Images/progress.gif");
That’s it you’re done now you have a simple wait page that will display to the user if they have Java Script enabled. If they don’t they simple will not notice anything. However there is one more issue with this method. If you are using the response object to redirect on the client side the HTTP headers have been sent so you will receive an error message.
To get around this problem you can use a little bit of tricky HTML. And create your own redirect method.
public void redirect(string p_redirectURI)
{
Response.ClearContent();
Response.Write("<head>");
Response.Write("<meta http-equiv=\"REFRESH\" content=\"0;url=" + p_redirectURI + "\">");
Response.Write("</head>");
Response.Flush();
}
This is my solution to the problem. You have any ideas or question please feel free to let me know.