国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET實現進度條

2024-07-10 13:06:06
字體:
來源:轉載
供稿:網友

商業源碼熱門下載www.html.org.cn

在網上查閱了很多相關資料,參照對比一番后自己整理了一下,做了個小例子。能夠實現根據后臺數據加載的進度在前臺動態更新進度條、進度條在頁面居中顯示、在進度條內顯示百分比,完成進度后隱藏進度條。個人感覺還是有一定的參考價值,貼出來先。

建立一個web工程,添加新項->html頁面,命名為progressbar.htm,內容如下:

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="mainwindow">
<head>
    <title>無標題頁</title>
    <script language="javascript">
        function setporgressbar(pos)
        {
            //設置進度條居中
            var screenheight = window["mainwindow"].offsetheight;
            var screenwidth = window["mainwindow"].offsetwidth;
            progressbarside.style.width = math.round(screenwidth / 2);
            progressbarside.style.left = math.round(screenwidth / 4);
            progressbarside.style.top = math.round(screenheight / 2);
            progressbarside.style.height = "21px";
            progressbarside.style.display = "";
            
            //設置進度條百分比                      
            progressbar.style.width = pos + "%";
            progresstext.innerhtml = pos + "%";
        }

        //完成后隱藏進度條
        function setcompleted()
        {      
            progressbarside.style.display = "none";
        }
     </script> 
</head>
    <body>
    <div id="progressbarside" >
        <div id="progressbar" ></div>
        <div id="progresstext" ></div>
    </div>
    </body>
</html>
后臺代碼,default.aspx.cs:

using system;
using system.data;
using system.configuration;
using system.web;
using system.web.security;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.webcontrols.webparts;
using system.web.ui.htmlcontrols;
using system.threading;
using system.io;

public partial class _default : system.web.ui.page
{
    private void beginprogress()
    {
        //根據progressbar.htm顯示進度條界面
        string templatefilename = path.combine(server.mappath("."), "progressbar.htm");
        streamreader reader = new streamreader(@templatefilename,system.text.encoding.getencoding("gb2312"));
        string html = reader.readtoend();
        reader.close();
        response.write(html);
        response.flush();
    }

    private void setprogress(int percent)
    {
        string jsblock = "<script>setporgressbar('" + percent.tostring() + "'); </script>";
        response.write(jsblock);
        response.flush();
    }

    private void finishprogress()
    {
        string jsblock = "<script>setcompleted();</script>";
        response.write(jsblock);
        response.flush();
    }

    private void page_load(object sender, system.eventargs e)
    {
        beginprogress();

        for (int i = 1; i <= 100; i++)
        {
            setprogress(i);

            //此處用線程休眠代替實際的操作,如加載數據等
            system.threading.thread.sleep(50);
        }

        finishprogress();
    }
}
前臺頁面代碼在此省略,可以放置任意控件。


 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安义县| 富顺县| 咸丰县| 浦县| 祥云县| 远安县| 灯塔市| 荃湾区| 定远县| 田阳县| 从江县| 香港| 文安县| 仙桃市| 奉贤区| 临海市| 迁西县| 竹北市| 潜江市| 达尔| 镇赉县| 盐源县| 健康| 高青县| 咸宁市| 大方县| 西贡区| 佛坪县| 出国| 雷山县| 饶平县| 安仁县| 肇源县| 中超| 三原县| 建始县| 扶沟县| 平原县| 安岳县| 京山县| 枝江市|