<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ★33°空間‰


                           ----★七彩服飾  【最潮拜☆日單精品】【Esprit】【Hotwind】滿150包郵-女裝-流行女裝    www.7color.hb.cn

                           ----智力比知識重要,素質(zhì)比智力重要,覺悟比素質(zhì)更重要
    posts - 110,comments - 35,trackbacks - 0

    網(wǎng)上已經(jīng)有很多Web進(jìn)度條的例子,但是很多都是估算時間,不能正真反應(yīng)任務(wù)的真實進(jìn)度。我自己結(jié)合多線程和ShowModalDialog制做了一個實時進(jìn)度條,原理很簡單:使用線程開始長時間的任務(wù),定義一個Session,當(dāng)任務(wù)進(jìn)行到不同的階段改變Session的值,線程開始的同時使用ShowModalDialog打開一個進(jìn)度條窗口,不斷刷新這個窗口獲取Session值,反應(yīng)出實時的進(jìn)度。下面就來看看具體的代碼:(文章結(jié)尾處下載源代碼)

    先新建一個Default.aspx頁面,
    客戶端代碼:

    <body MS_POSITIONING="GridLayout">
    ??? <form id="Form1" method="post" runat="server">
    ??????????? <br>
    ??????????? <br>
    ??????????? <asp:Button id="Button1" runat="server" Text="Start Long Task!"></asp:Button>
    ??? </form>
    </body>
    服務(wù)器端代碼:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Text;

    namespace WebProgressBar
    {
    ??? /**//// <summary>
    ??? /// Summary description for _Default.
    ??? /// </summary>
    ??? public class _Default : System.Web.UI.Page
    ??? {
    ??????? protected System.Web.UI.WebControls.Button Button1;
    ???
    ??????? private void Page_Load(object sender, System.EventArgs e)
    ??????? {
    ??????????? // Put user code to initialize the page here
    ??????? }

    ??????? Web Form Designer generated code#region Web Form Designer generated code
    ??????? override protected void OnInit(EventArgs e)
    ??????? {
    ??????????? //
    ??????????? // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    ??????????? //
    ??????????? InitializeComponent();
    ??????????? base.OnInit(e);
    ??????? }
    ???????
    ??????? /**//// <summary>
    ??????? /// Required method for Designer support - do not modify
    ??????? /// the contents of this method with the code editor.
    ??????? /// </summary>
    ??????? private void InitializeComponent()
    ??????? {???
    ??????????? this.Button1.Click += new System.EventHandler(this.Button1_Click);
    ??????????? this.Load += new System.EventHandler(this.Page_Load);

    ??????? }
    ??????? #endregion

    ??????? private void LongTask()
    ??????? {
    ??????????? //模擬長時間任務(wù)
    ??????????? //每個循環(huán)模擬任務(wù)進(jìn)行到不同的階段
    ??????????? for(int i=0;i<11;i++)
    ??????????? {
    ??????????????? System.Threading.Thread.Sleep(1000);
    ??????????????? //設(shè)置每個階段的state值,用來顯示當(dāng)前的進(jìn)度
    ??????????????? Session["State"] = i+1;
    ??????????? }
    ??????????? //任務(wù)結(jié)束
    ??????????? Session["State"] = 100;

    ??????? }

    ??????? public static void OpenProgressBar(System.Web.UI.Page Page)
    ??????? {
    ??????????? StringBuilder sbScript = new StringBuilder();

    ??????????? sbScript.Append("<script language='javascript' type='text/javascript'>\n");
    ??????????? sbScript.Append("<!--\n");
    ??????????? //需要IE5.5以上支持
    ??????????? sbScript.Append("window.showModalDialog('Progress.aspx','','dialogHeight: 100px; dialogWidth: 350px; edge: Raised; center: Yes; help: No; resizable: No; status: No;scroll:No;');\n");
    ??????????? //IE5.5以下使用window.open
    ??????????? //sbScript.Append("window.open('Progress.aspx','', 'height=100, width=350, toolbar =no, menubar=no, scrollbars=no, resizable=no, location=no, status=no');\n");
    ??????????? sbScript.Append("http:// -->\n");
    ??????????? sbScript.Append("</script>\n");

    ??????????? Page.RegisterClientScriptBlock("OpenProgressBar", sbScript.ToString());
    ??????? }

    ??????? private void Button1_Click(object sender, System.EventArgs e)
    ??????? {
    ??????????? System.Threading.Thread thread=new System.Threading.Thread(new System.Threading.ThreadStart(LongTask));
    ??????????? thread.Start();

    ??????????? Session["State"]=1;
    ??????????? OpenProgressBar(this.Page);
    ??????? }
    ??? }
    }


    新建一個進(jìn)度條頁面Progress.aspx
    客戶端:
    在head中加入<base target="_self">
    <body MS_POSITIONING="GridLayout">
    ??????? <form id="Form1" method="post" runat="server">
    ??????????? <asp:Label id="lblMessages" runat="server"></asp:Label>
    ??????????? <asp:Panel id="panelBarSide" runat="server" Width="300px" BorderStyle="Solid" BorderWidth="1px"
    ??????????????? ForeColor="Silver">
    ??????????????? <asp:Panel id="panelProgress" runat="server" Width="10px" BackColor="Green"></asp:Panel>
    ??????????? </asp:Panel>
    ??????????? <asp:Label id="lblPercent" runat="server" ForeColor="Blue"></asp:Label>
    ??????? </form>
    </body>
    服務(wù)器端:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;

    namespace WebProgressBar
    {
    ??? /**//// <summary>
    ??? /// Summary description for Progress.
    ??? /// </summary>
    ??? public class Progress : System.Web.UI.Page
    ??? {
    ??????? protected System.Web.UI.WebControls.Label lblMessages;
    ??????? protected System.Web.UI.WebControls.Panel panelProgress;
    ??????? protected System.Web.UI.WebControls.Panel panelBarSide;
    ??????? protected System.Web.UI.WebControls.Label lblPercent;
    ???
    ??????? private int state = 0;
    ??????? private void Page_Load(object sender, System.EventArgs e)
    ??????? {
    ??????????? // Put user code to initialize the page here
    ??????????? if(Session["State"]!=null)
    ??????????? {
    ??????????????? state = Convert.ToInt32(Session["State"].ToString());
    ??????????? }
    ??????????? else
    ??????????? {
    ??????????????? Session["State"]=0;
    ??????????? }
    ??????????? if(state>0&&state<=10)
    ??????????? {
    ??????????????? this.lblMessages.Text = "Task undertaking!";
    ??????????????? this.panelProgress.Width = state*30;
    ??????????????? this.lblPercent.Text = state*10 + "%";
    ??????????????? Page.RegisterStartupScript("","<script>window.setTimeout('window.Form1.submit()',100);</script>");
    ??????????? }
    ??????????? if(state==100)
    ??????????? {
    ??????????????? this.panelProgress.Visible = false;
    ??????????????? this.panelBarSide.Visible = false;
    ??????????????? this.lblMessages.Text = "Task Completed!";
    ??????????????? Page.RegisterStartupScript("","<script>window.close();</script>");
    ??????????? }
    ??????? }

    ??????? Web Form Designer generated code#region Web Form Designer generated code
    ??????? override protected void OnInit(EventArgs e)
    ??????? {
    ??????????? //
    ??????????? // CODEGEN: This call is required by the ASP.NET Web Form Designer.
    ??????????? //
    ??????????? InitializeComponent();
    ??????????? base.OnInit(e);
    ??????? }
    ???????
    ??????? /**//// <summary>
    ??????? /// Required method for Designer support - do not modify
    ??????? /// the contents of this method with the code editor.
    ??????? /// </summary>
    ??????? private void InitializeComponent()
    ??????? {???
    ??????????? this.Load += new System.EventHandler(this.Page_Load);

    ??????? }
    ??????? #endregion
    ??? }
    }

    posted on 2007-03-23 10:28 圣域飛俠 閱讀(241) 評論(0)  編輯  收藏 所屬分類: 轉(zhuǎn)載
    主站蜘蛛池模板: 免费国产成人18在线观看| 五月天婷婷免费视频| 午夜免费福利视频| 亚洲AV永久无码精品| 国产又黄又爽又大的免费视频 | 亚洲欧美成人av在线观看| 日韩免费一区二区三区在线| 亚洲 日韩 色 图网站| 四虎成人免费观看在线网址| 精品亚洲av无码一区二区柚蜜| 免费国产高清视频| 一区二区三区免费电影| 国产亚洲综合网曝门系列| 四虎影视在线影院在线观看免费视频 | 国产v亚洲v天堂无码网站| 久久99免费视频| 亚洲午夜精品在线| 免费毛片网站在线观看| 老外毛片免费视频播放| 亚洲无人区午夜福利码高清完整版| 永久免费A∨片在线观看| 亚洲黑人嫩小videos| 成年女人毛片免费播放人| 自拍偷自拍亚洲精品播放| 国产亚洲精久久久久久无码AV| 国产成年无码久久久免费| 亚洲高清无在码在线无弹窗| 在线观看免费为成年视频| 一级成人a免费视频| 久久亚洲美女精品国产精品 | 大地资源免费更新在线播放| 美女黄色免费网站| 亚洲Av无码精品色午夜| 成年美女黄网站色大免费视频 | 99久久人妻精品免费一区| 亚洲色大成WWW亚洲女子| 亚洲色欲色欲www在线丝| 在线视频免费观看爽爽爽| 四虎国产精品永免费| 亚洲视频免费观看| 亚洲国产av一区二区三区|