ASP: Progress Bar
Introduction
Author: Martin WarningYear: 2007
License: Free
This code shows an example of a progress bar that is displayed during the execution of an ASP cycle. With ASP the client browser is not updated until all ASP is executed. This doesn't allow any form of progress bar to displayed on the client side during the execution of our ASP code. The Response.Flush object allows us to send data to the client browser during the execution of the ASP code. The Response.Flush object will write whatever HTML (CSS & JavaScript as well) that have already been created up till the point the Response.Flush object is encountered. So the Response.Flush object does allow us to send information the client browser during the execution of our ASP code.
The following example shows an example code to show how this progress bar could be implemented. In this case we use a For loop with an arbitrary long cycle. This cycle will run at different speeds based on your server software. You would implement this code in your own cycles like a database loop cycle. If this code executes to quickly you can increase the value of intCycle.
Code
Languages:- XHTML
- CSS
- ASP
- VBScript
<% Response.Buffer = True %>The following code is an example cycle with progress bar:
<%
' Declare and initialize the variables
Dim intCycle : intCycle = 3000000
Dim i
Dim j : j = 0
Dim x : x = 0
' i and intCycle are used for the cycle in this example
' j is used for the 10% spacer image
' x is used for the 1% bar image is
Response.Write("<img src=""progress.gif"" alt="""" /><br />")
' Start the cycle
For i = 1 To intCycle
' Every 1% of completion a bar image is written to the page
If x = (intCycle/100) Then
Response.Write("<img src=""bar.gif"" alt=""% Completed"" width=""3"" height=""20"" />")
x = 0
If j = 10 Then
' Every 10% of completion a spacer images is written to the page
Response.Write("<img src=""bar_spacer.gif"" alt="""" width=""1"" height=""20"" />")
j = 0
Else
j = j + 1
End If
' Write html to client browser
Response.Flush
Else
x = x + 1
End If
Next
%>