在c#中加载页面时显示加载图像
本文关键字:加载 显示 图像 | 更新日期: 2023-09-27 18:20:49
在c#中加载页面时,我需要显示一个加载图像。
我尝试过使用这个解决方案,但没有成功,因为错误是:
Line 72: this.Response.Write(@"dots++;");
在解决这个问题时,如果你能给我任何帮助,我将不胜感激。
这是我的代码:
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
PleaseWait();
}
protected void PleaseWait()
{
this.Response.Write("<meta http-equiv=X-UA-Compatible content=IE=8>");
this.Response.Write(@"<style type=text/css media=all>");
this.Response.Write(@".loading");
this.Response.Write(@"{");
this.Response.Write(@"text-align: center;");
this.Response.Write(@"padding-top: 30px;");
this.Response.Write(@"border-width: 1px solid #000;");
this.Response.Write(@"width: 300px;");
this.Response.Write(@"height: 100px;");
this.Response.Write(@"-ms-filter: alpha(opacity=90);");
this.Response.Write(@"-ms-opacity: 0.90;");
this.Response.Write(@"border-style: solid;");
this.Response.Write(@"background-color: #FFFFFF;");
this.Response.Write(@"position: absolute;");
this.Response.Write(@"font-family: Trebuchet MS;");
this.Response.Write(@"font-size: small;");
this.Response.Write(@"position: absolute;");
this.Response.Write(@"top: 0;");
this.Response.Write(@"bottom: 0;");
this.Response.Write(@"left: 0;");
this.Response.Write(@"right: 0;");
this.Response.Write(@"margin: auto;");
this.Response.Write(@"display: block;");
this.Response.Write(@"background: url('/images/wait01.gif') no-repeat center;");
this.Response.Write(@"}");
this.Response.Write(@"</style>");
this.Response.Write(@"<div id=mydiv class=loading> </div>");
this.Response.Write(@"<script>mydiv.innerText = '';");
this.Response.Write(@"</script>");
this.Response.Write(@"<script type=text/javascript language="javascript">;");
this.Response.Write(@"var dots = 0;");
this.Response.Write(@"var dotmax = 10;");
this.Response.Write(@"function ShowWait()");
this.Response.Write(@"{");
this.Response.Write(@"var output;");
this.Response.Write(@"output = '" + "Please wait..." + "';");
this.Response.Write(@"dots++;");
this.Response.Write(@"if(dots>=dotmax)dots=1;");
this.Response.Write(@"for(var x = 0;");
this.Response.Write(@"x < dots;x++)");
this.Response.Write(@"{");
this.Response.Write(@"output += '.';");
this.Response.Write(@"}");
this.Response.Write(@"mydiv.innerText = output;");
this.Response.Write(@"}");
this.Response.Write(@"function StartShowWait()");
this.Response.Write(@"{");
this.Response.Write(@"mydiv.style.visibility = 'visible'; ");
this.Response.Write(@"window.setInterval('ShowWait()',1000);");
this.Response.Write(@"}");
this.Response.Write(@"function HideWait()");
this.Response.Write(@"{");
this.Response.Write(@"mydiv.style.visibility = 'hidden';");
this.Response.Write(@"window.clearInterval();");
this.Response.Write(@"}");
this.Response.Write(@"StartShowWait();");
this.Response.Write(@"</script>");
this.Response.Flush();
System.Threading.Thread.Sleep(500);
}
</script>
我想您想在页面加载时显示一个加载图像。
如果是这种情况,则可以使用Jquery Load事件来显示加载图像。
试试这个:http://jsbin.com/izetOcAP/2/edit
使用响应。这样写太疯狂了!你可以做到这一点并在这个过程中保持头发的一种方法是:
html
<body class="load">
<p>My hair is still here.</p>
</body>
css
.load{
background-color:#e6e6e6;
}
.load.complete{
background-color:transparent;
}
js
$(document).ready(function(){
this.body.className = 'load complete';
})
下面是一个非常快速的例子http://jsfiddle.net/rp6oourg/.