在ASP.NET中显示进度条
2024-07-10 12:57:17
供稿:网友
对于加载时间比较长的asp.net页面,我们可以在客户端浏览器中显示进度条来显示页面正在装载。下面就是具体的实现过程:
新建项目,名字为webportal,在项目类型中选择visual c#项目或者visual basic项目都可;
在模板类型中选择asp.net web应用程序;
位置里输入:http://localhost/webportal;
添加新项:名字为showprogress的web窗体。
在您的web窗体showprogress.aspx上添加任何其他的web服务器控件。
在showprogress.aspx上单击右键,点“查看代码”,在最上面输入:
visual c# .net代码
using system.threading;
visual basic .net代码
imports system.threading
在page_load事件里输入: visual c# .net代码
response.write("<div id='mydiv' >");
response.write("_");
response.write("</div>");
response.write("<script>mydiv.innertext = '';</script>");
response.write("<script language=javascript>;");
response.write("var dots = 0;var dotmax = 10;function showwait()");
response.write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;");
response.write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innertext = output;}");
response.write("function startshowwait(){mydiv.style.visibility = 'visible'; ");
response.write("window.setinterval('showwait()',1000);}");
response.write("function hidewait(){mydiv.style.visibility = 'hidden';");
response.write("window.clearinterval();}");
response.write("startshowwait();</script>");
response.flush();
thread.sleep(10000);
visual basic .net代码
response.write("<div id='mydiv' >")
response.write("_")
response.write("</div>")
response.write("<script>mydiv.innertext = '';</script>")
response.write("<script language=javascript>;")
response.write("var dots = 0;var dotmax = 10;function showwait()")
response.write("{var output; output = '正在装载页面';dots++;if(dots>=dotmax)dots=1;")
response.write("for(var x = 0;x < dots;x++){output += '·';}mydiv.innertext = output;}")
response.write("function startshowwait(){mydiv.style.visibility = 'visible'; ")
response.write("window.setinterval('showwait()',1000);}")
response.write("function hidewait(){mydiv.style.visibility='hidden';")
response.write("window.clearinterval();}")
response.write("startshowwait();</script>")
response.flush()
thread.sleep(10000)
在showprogress.aspx窗体的html的中输入:
<script>
hidewait();
</script>
点在浏览器中查看即可。