我需要在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>
答案 0 :(得分:1)
答案 1 :(得分:0)
使用Response.Writes就是这样疯狂!你可以做到这一点并保持头发的一种方法是:
<强> 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/的小提琴。