The original article is an article I have found when I need the progress bar, explain the details and accompany them. I added my own modification on the basis of the original text: increase the thread tension and put the use of the progress bar in the sub-thread. This is my first translation article, please refer to you. In the original text, please contact the reference.
Who said that the progress bar can not be used in a web application? I think it can be. This article introduces the quality and interface friendship of the web application by using progress bar during processing ends. In fact, if a web application has been running in a stateless and no connection, it is easy to think that things have been over. But this article describes the progress bar that does not use any ActiveX control and a messy java applets will help improve this.
The key to the use of progress bar in a web application is that the browser has the ability to display the page before all pages are loaded. We will use this characteristic to generate steps and send a page to the client. First, we will use HTML to generate a perfect and beautiful schedule, then we dynamically send JavaScript blocks to update the progress bar. Of course, all the above content is implemented before disconnecting the user request. In C #, Response.Write allows us to join custom content to the cache and response.fluse () allows us to send content in all cache zones to the user's browser.
first step:
The first step allows us to create a progress bar, we use ProgressBar.aspx. As mentioned above, we gradually generate and send a page to the client. First, we will use HTML to generate a perfect and beautiful progress bar. The required HTML code can be obtained in the progravelbar.htm in the first defined, so the first thing is to load it and send the data stream to the client's browser, add the following lines in Page_LOAD of ProgressBar.aspx:
StreamReader SR = New StreamReader (StrfileName, System.Text.Encoding.default);
String strHtml = sr.readtoend ();
Response.write (strHTML);
sr.close ();
Response.flush ();
The following is the HTML code of ProgressBar.htm, (Translation: The author puts the script function in another JS file, but I am still in this static page)
Function setPGB (PGBID, PGBVALUE)
{
IF (pgbvalue <= 100)
{
IF (lblobj = document.getlementByid (pgbid _ label ')))
{
LBlobj.innerHTML = PGBValue '%'; // Change the Label Value
Now we can start updating the progress bar, which is a very important part because this part can make your progress entry. (Translation, it turned out to use random increase 15 times until the loading is completed, this article only uses the uniformity from 1 to 100, and the following is uncharacted)
First we open a thread, add the following code in Page_Load:
Thread thread = New Thread (New ThreadStart (threadproc);