2014-09-05 249 views
-2

我需要显示加载图像时,页面加载在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>&nbsp;</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> 
+5

只是...没有。删除所有'Response.Write',像使用ASP.NET应该使用的那样(使用控件,而不是'Response.Write'),并让浏览器显示它正在加载。或者再次解释你实际得到的错误:不,你不想这样做。您也无法在页面加载时在页面上显示加载图像,因为需要加载页面才能显示图像。 – CodeCaster 2014-09-05 12:15:46

回答

1

我猜你想在页面加载显示加载图像。

如果是这种情况,您可以使用Jquery Load事件来显示加载图像。

试试这个:http://jsbin.com/izetOcAP/2/edit

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/的小提琴。

相关问题