1
2
3
4
26
27
28
29
30
31
2
3
4
26
27
28
正在加载...
29
30
31
接下来,在 Default.aspx 文件中,我们将加载上述 HTML 文件并模拟处理过程,以动态更新进度条:
1protected void Page_Load(object sender, EventArgs e) {
2 // 加载进度条模板文件
3 string templatePath = Path.Combine(Server.MapPath('.'), "ProgressBar.htm");
4 using (StreamReader reader = new StreamReader(templatePath, System.Text.Encoding.GetEncoding("gb2312"))) {
5 string htmlCOntent= reader.ReadToEnd();
6 Response.Write(htmlContent);
7 Response.Flush();
8 System.Threading.Thread.Sleep(200);
9 }
10
11 // 模拟处理过程,更新进度条
12 for (int i = 1; i <= 100; i++) {
13 System.Threading.Thread.Sleep(10);
14 string jsScript = $"";
15 Response.Write(jsScript);
16 Response.Flush();
17 }
18
19 // 处理完成后,更新最终消息
20 string completiOnScript= "";
21 Response.Write(completionScript);
22 Response.Flush();
23}
2 // 加载进度条模板文件
3 string templatePath = Path.Combine(Server.MapPath('.'), "ProgressBar.htm");
4 using (StreamReader reader = new StreamReader(templatePath, System.Text.Encoding.GetEncoding("gb2312"))) {
5 string htmlCOntent= reader.ReadToEnd();
6 Response.Write(htmlContent);
7 Response.Flush();
8 System.Threading.Thread.Sleep(200);
9 }
10
11 // 模拟处理过程,更新进度条
12 for (int i = 1; i <= 100; i++) {
13 System.Threading.Thread.Sleep(10);
14 string jsScript = $"";
15 Response.Write(jsScript);
16 Response.Flush();
17 }
18
19 // 处理完成后,更新最终消息
20 string completiOnScript= "";
21 Response.Write(completionScript);
22 Response.Flush();
23}
运行 Default.aspx 页面后,可以看到如下效果:
本文参考自:http://www.cnblogs.com/anjou/archive/2006/10/27/541741.html