免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
教你制做Web實(shí)時(shí)進(jìn)度條http://pubimage.360doc.com/an13.gif-.NET教程,Web Service開(kāi)發(fā)

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

先新建一個(gè)default.aspx頁(yè)面,
客戶端代碼:

<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()
        {
            //模擬長(zhǎng)時(shí)間任務(wù)
            //每個(gè)循環(huán)模擬任務(wù)進(jìn)行到不同的階段
            for(int i=0;i<11;i++)
            {
                system.threading.thread.sleep(1000);
                //設(shè)置每個(gè)階段的state值,用來(lái)顯示當(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);
        }
    }
}


新建一個(gè)進(jìn)度條頁(yè)面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
    }
}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
母板頁(yè)、用戶控件、視圖狀態(tài)
asp.net 2.0 + sqlserver2005 數(shù)據(jù)依賴緩存 - 錢(qián)途無(wú)梁 - 博...
多文件上傳
使用Asp.net動(dòng)態(tài)生成控件的使用總結(jié)! - 秋風(fēng)夜狼 - sweet_chenqian...
gridview分頁(yè)模型
UpdatePanel的使用(上)
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服