asp.net how to generate a static page, refer to the following article:
Http://www.jb51.net/article/18175.htm
And we use simulations, just let the thread delay execution. For example, the following code:
Copy Code code as follows:
for (int i = 0; i < i++)
{
DateTime starttime = DateTime.Now;
Response.Write (i + "-------------Execution time:" + starttime.tostring () + "<br/>");
Thread.Sleep (1000);
}
Show Results:
Time is not the same, if the thread is not delayed, then the time here is the same. And what we need to do is just:
Copy Code code as follows:
Don't forget to introduce namespaces:
Copy Code code as follows:
And the output is a one-time full output, not every second output line (is achievable, later will be mentioned). How nice it would be to output a line every second if you write it that way. Based on this principle, if you only need to make a build static that indicates that the process is being generated without the need for a progress display, you can do this:
Copy Code code as follows:
<asp:button id= "Btnok" runat= "onclick=" Btnok_click "text=" generates a static progress bar "onclientclick=" createload () "/>"
In the button button, add a
Copy Code code as follows:
Onclientclick= "Createload ()"
Indicates that the client event is triggered while the button is pressed, and the client creates a waiting div. The effect is as follows:
The Creatload function code is as follows:
Copy Code code as follows:
function Createload () {
var loaddiv = document.createelement ("div");
Loaddiv.style.width = "200px";
Loaddiv.style.height = "100px";
Loaddiv.style.border = "1px solid #000000";
Loaddiv.style.fontSize = "12px";
Loaddiv.style.lineHeight = "100px";
Loaddiv.style.backgroundColor = "#cccccc";
loaddiv.style.textAlign = "center";
loaddiv.innerhtml = "Please wait ...";
Document.body.appendChild (LOADDIV);
}
After the execution, the div automatically disappears.
With the above bedding, now began to get to the point, we must be to achieve every second output of this effect of a row, and this is actually very easy to achieve, as long as the page does not buffer can be coupled with the thread delay can be done. To close a buffer in the page:
Buffer= "false"
Next, we'll just find a progress bar effect, and then count the total number of articles that need to generate a static page, according to the current generated article for the first few records, to calculate the total number of executions have been carried out. Then real-time call a JS function to achieve progress block changes, OK.
About the progress bar, we can find a casual internet, I used here a progress bar effect, because simple. Http://www.jb51.net/article/18177.htm
Of course, this progress bar is not suitable for our current specific use, the key parts of JS need to be modified as follows:
Copy Code code as follows:
I is the record that is currently executing, Count is total
For example, the total number of static numbers to be generated is 100, so now execute to 5%, then the progress bar into 5% places
function Loadbar (i,count) {
var a = parsefloat (I*100/count);
$ ("bar"). Style.width = a + "%";
if ($ ("bar"). Style.width = = "100%") {
$ ("bar"). InnerHTML = "complete";
}else{
$ ("bar"). InnerHTML = a + "%";
}
}
The following is the key to the key C # backend code, which, according to the above function, outputs code similar to the following, based primarily on the record being executed:
Copy Code code as follows:
< Script>loadbar (1,10); </script><script>loadbar (2,10); </script><script>loadbar ( 3,10); </script><script>loadbar (4,10); </script><script>loadbar (5,10);</script> <script>loadbar (6,10); </script><script>loadbar (7,10); </script><script>loadbar ( 8,10); </script><script>loadbar (9,10); </script><script>loadbar (10,10);</script>
According to such output, the output of these characters must be in the JS,CSS, and the relevant HTML code before the output, otherwise in the head of the output, certainly not. Because this function is not in front of it, it executes to this function. (Do you want to use the literal control to control its output position?) You can try it by yourself, what's the result? So, simply we put the relevant progress bar code one-time output, you can make it into an HTML file, this is also on the Internet to see an article when the practice. Known as bar.htm
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> progress bar </title>
<script language= "javascript" type= "Text/javascript" >
function $ (obj) {
return document.getElementById (obj);
}
I is the record that is currently executing, Count is total
For example, the total number of static numbers to be generated is 100, so now execute to 5%, then the progress bar into 5% places
function Loadbar (i,count) {
var a = parsefloat (I*100/count);
$ ("bar"). Style.width = a + "%";
if ($ ("bar"). Style.width = = "100%") {
$ ("bar"). InnerHTML = "complete";
}else{
$ ("bar"). InnerHTML = a + "%";
}
}
</script>
<style type= "Text/css" >
body{
Text-align:center;
font-size:12px;
}
. graph{
width:450px;
border:1px solid #F8B3D0;
height:25px;
margin:0 Auto;
}
#bar {
Display:block;
Background: #FFE7F4;
Float:left;
height:100%;
Text-align:center;
}
</style>
<body>
<form id= "Form1" runat= "Server" >
<div>
<div class= "graph" >
<strong id= "Bar" style= "width:1%;" ></strong>
</div>
</div>
</form>
</body>
And the code we use to simulate is as follows:
Copy Code code as follows:
for (int i = 0; i < i++)
{
if (i = = 0)
{
String strFileName = Fileobj.readfile (Server.MapPath ("bar.htm"));
Response.Write (strFileName);
}
Response.Write ("<script>loadbar (" + (i + 1) + ", Ten);</script>");
Thread.Sleep (1000);
}
Fileobj.readfile is read this HTM file, this function and its related file operation class, you can get in this article! Http://www.jb51.net/article/15125.htm Plus Conditional statement
Copy Code code as follows:
It is because the bar.htm only needs to output once after it is read out. The final effect is as follows:
But it is dynamic oh, but only the simulation of the code to generate static when the relevant function code, of course, can also be other. Of course, can also use the Ajax method, there is no time to thank this aspect of the implementation of the article.