• Asp.net添加上传进度条


    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();
        }
    }

    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 type="text/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" style="position:absolute;height:21x;100px;color:Silver;border-1px;border-style:Solid;display:none">
            <div id="ProgressBar" style="position:absolute;height:21px;0%;background-color:#3366FF"></div>
            <div id="ProgressText" style="position:absolute;height:21px;100%;text-align:center"></div>
        </div>
        </body>
    </html>


     

  • 相关阅读:
    新博客第一篇,字符串 Unicode 转义
    C# 泛型方法的类型推断
    一个改进 LRU 算法的缓冲池 update 2013.7.15
    C# 判断类型间能否隐式或强制类型转换,以及开放泛型类型转换 update 2015.02.03
    C# 词法分析器(三)正则表达式
    java面试题(二)
    Map的迭代
    Spring aop切面插入事物回滚
    Log4J的配置
    js中将yyyyMMdd格式的日期转换
  • 原文地址:https://www.cnblogs.com/wangyhua/p/4050664.html
Copyright © 2020-2023  润新知