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

ASP.NET實現進度條

2013-11-13 09:54:10  來源: .NET編程 

  終於找到一個ASPNET實現進度條的例子

  建立一個WEB工程添加新項>HTML頁面命名為內容如下

  <!DOCTYPE html PUBLIC //WC//DTD XHTML Transitional//EN transitionaldtd>

  <html xmlns= id=mainWindow>

  <head>

  <title>無標題頁</title>

  <script language=javascript>

  function SetPorgressBar(pos)

  {

  //設置進度條居中

  var screenHeight = window[mainWindow]offsetHeight;

  var screenWidth = window[mainWindow]offsetWidth;

  ProgressBarSidestylewidth = Mathround(screenWidth / );

  ProgressBarSidestyleleft = Mathround(screenWidth / );

  ProgressBarSidestyletop = Mathround(screenHeight / );

  ProgressBarSidestyleheight = px;

  ProgressBarSidestyledisplay = ;

  //設置進度條百分比

  ProgressBarstylewidth = pos + %;

  ProgressTextinnerHTML = pos + %;

  }

  //完成後隱藏進度條

  function SetCompleted()

  {

  ProgressBarSidestyledisplay = none;

  }

  </script>

  </head>

  <body>

  <div id=ProgressBarSide >

  <div id=ProgressBar ></div>

  <div id=ProgressText ></div>

  </div>

  </body>

  </html>

  後台代碼Defaultaspxcs

  using System;

  using SystemData;

  using SystemConfiguration;

  using SystemWeb;

  using SystemWebSecurity;

  using SystemWebUI;

  using SystemWebUIWebControls;

  using SystemWebUIWebControlsWebParts;

  using SystemWebUIHtmlControls;

  using SystemThreading;

  using SystemIO;

  public partial class _Default : SystemWebUIPage

  {

  private void beginProgress()

  {

  //根據顯示進度條界面

  string templateFileName = PathCombine(ServerMapPath() );

  StreamReader reader = new StreamReader(@templateFileNameSystemTextEncodingGetEncoding(GB));

  string html = readerReadToEnd();

  readerClose();

  ResponseWrite(html);

  ResponseFlush();

  }

  private void setProgress(int percent)

  {

  string jsBlock = <script>SetPorgressBar( + percentToString() + ); </script>;

  ResponseWrite(jsBlock);

  ResponseFlush();

  }

  private void finishProgress()

  {

  string jsBlock = <script>SetCompleted();</script>;

  ResponseWrite(jsBlock);

  ResponseFlush();

  }

  private void Page_Load(object sender SystemEventArgs e)

  {

  beginProgress();

  for (int i = ; i <= ; i++)

  {

  setProgress(i);

  //此處用線程休眠代替實際的操作如加載數據等

  SystemThreadingThreadSleep();

  }

  finishProgress();

  }

  }


From:http://tw.wingwit.com/Article/program/net/201311/11915.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.