熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

在ASP.NET中顯示進度條

2013-11-13 10:03:46  來源: .NET編程 

  對於加載時間比較長的ASPNET頁面我們可以在客戶端浏覽器中顯示進度條來顯示頁面正在裝載下面就是具體的實現過程
  
  新建項目名字為WebPortal在項目類型中選擇Visual C#項目或者Visual Basic項目都可
  在模板類型中選擇ASPNET Web應用程序
  位置裡輸入//localhost/WebPortal
  添加新項名字為ShowProgress的Web窗體
  在您的Web窗體ShowProgressaspx上添加任何其他的Web服務器控件
  在ShowProgressaspx上單擊右鍵查看代碼在最上面輸入
  Visual C# NET代碼
  using SystemThreading;
  
  Visual Basic NET代碼
  Imports SystemThreading
  
  在Page_Load事件裡輸入 Visual C# NET代碼
  ResponseWrite(<div id=mydiv >);
  ResponseWrite(_);
  ResponseWrite(</div>);
  ResponseWrite(<script>mydivinnerText = ;</script>);
  ResponseWrite(<script language=javascript>;);
  ResponseWrite(var dots = ;var dotmax = ;function ShowWait());
  ResponseWrite({var output; output = 正在裝載頁面;dots++;if(dots>=dotmax)dots=;);
  ResponseWrite(for(var x = ;x < dots;x++){output += ·;}mydivinnerText = output;});
  ResponseWrite(function StartShowWait(){mydivstylevisibility = visible; );
  ResponseWrite(windowsetInterval(ShowWait());});
  ResponseWrite(function HideWait(){mydivstylevisibility = hidden;);
  ResponseWrite(windowclearInterval();});
  ResponseWrite(StartShowWait();</script>);
  ResponseFlush();
  ThreadSleep();
  
  Visual Basic NET代碼
  ResponseWrite(<div id=mydiv >)
  ResponseWrite(_)
  ResponseWrite(</div>)
  ResponseWrite(<script>mydivinnerText = ;</script>)
  ResponseWrite(<script language=javascript>;)
  ResponseWrite(var dots = ;var dotmax = ;function ShowWait())
  ResponseWrite({var output; output = 正在裝載頁面;dots++;if(dots>=dotmax)dots=;)
  ResponseWrite(for(var x = ;x < dots;x++){output += ·;}mydivinnerText = output;})
  ResponseWrite(function StartShowWait(){mydivstylevisibility = visible; )
  ResponseWrite(windowsetInterval(ShowWait());})
  ResponseWrite(function HideWait(){mydivstylevisibility=hidden;)
  ResponseWrite(windowclearInterval();})
  ResponseWrite(StartShowWait();</script>)
  ResponseFlush()
  ThreadSleep()
  
  在ShowProgressaspx窗體的html的中輸入
  <script>
  HideWait();
  </script>
  
  點在浏覽器中查看即可
From:http://tw.wingwit.com/Article/program/net/201311/12446.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.