我需要顯示加載圖像時,頁面加載在C#中。顯示一個加載圖像,當頁面加載在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>
只是...沒有。刪除所有'Response.Write',像使用ASP.NET應該使用的那樣(使用控件,而不是'Response.Write'),並讓瀏覽器顯示它正在加載。或者再次解釋你實際得到的錯誤:不,你不想這樣做。您也無法在頁面加載時在頁面上顯示加載圖像,因爲需要加載頁面才能顯示圖像。 – CodeCaster 2014-09-05 12:15:46