我们先看下效果

我点击了按钮后他会显示进度页面,进度完成后,进度条消失,其实也是比较简单的了。

我们需要一个进度条代码文件ProgressBar.htm(注意:是没有head这些标签的)

<script language="javascript">
function SetPorgressBar(pos) {
//设置进度条居中 var screenWidth = document.body.offsetWidth;
ProgressBarSide.style.width = Math.round(screenWidth / 2) + "px";
ProgressBarSide.style.left = Math.round(screenWidth / 4) + "px";
ProgressBarSide.style.top = "50px";
ProgressBarSide.style.height = "21px";
ProgressBarSide.style.display = "block"; //设置进度条百分比
ProgressBar.style.width = pos + "%";
ProgressText.innerHTML = pos + "%";
} function SetMaxValue(maxValue) {
ProgressBarSide.style.width = maxValue + "px";
} //完成后隐藏进度条
function SetCompleted() {
ProgressBarSide.style.display = "none";
} function SetTitle(title) {
ProgressTitle.innerHTML = title;
}
</script>
<div id="ProgressBarSide" style="position: absolute; height: 21px; width: 100px;
color: Silver; border-width: 1px; border-style: Solid; display: block">
<div id="ProgressBar" style="position: absolute; height: 21px; width: 0%; background-color: #1475BB">
</div>
<div id="ProgressText" style="position: absolute; height: 21px; width: 100%; text-align: center">
</div>
<div id="ProgressTitle" style="position: absolute; height: 21px; top: 21px; width: 100%;
text-align: center">
</div>
</div>

然后需要一个进度条类ProgressBar.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO; namespace ZhuoYueE.Dop.Web.UI
{
/// <summary>
///显示进度条
/// </summary>
public class ProgressBar : System.Web.UI.Page
{
/// <summary>
/// 最大值
/// </summary>
private int MaxValue
{
get
{
if (ViewState["MaxValue"] == null)
{
return ;
}
else
{
return Convert.ToInt32(ViewState["MaxValue"]);
}
}
set
{
ViewState["MaxValue"] = value;
}
}
/// <summary>
/// 当前值
/// </summary>
private int ThisValue
{
get
{
if (ViewState["ThisValue"] == null)
{
return ;
}
else
{
return Convert.ToInt32(ViewState["ThisValue"]);
}
}
set
{
ViewState["ThisValue"] = value;
}
}
/// <summary>
/// 当前页面
/// </summary>
System.Web.UI.Page m_page;
/// <summary>
/// 功能描述:构造函数
/// 作  者:huangzh
/// 创建日期:2016-05-06 11:54:34
/// 任务编号:
/// </summary>
/// <param name="page">当前页面</param>
public ProgressBar(System.Web.UI.Page page)
{
m_page = page;
} public void SetMaxValue(int intMaxValue)
{
MaxValue = intMaxValue;
} /// <summary>
/// 功能描述:初始化进度条
/// 作  者:huangzh
/// 创建日期:2016-05-06 11:55:26
/// 任务编号:
/// </summary>
public void InitProgress()
{
//根据ProgressBar.htm显示进度条界面
string templateFileName = AppDomain.CurrentDomain.BaseDirectory + "ProgressBar.htm";
StreamReader reader = new StreamReader(@templateFileName, System.Text.Encoding.GetEncoding("GB2312"));
string strhtml = reader.ReadToEnd();
reader.Close();
m_page.Response.Write(strhtml);
m_page.Response.Flush();
} /// <summary>
/// 功能描述:设置标题
/// 作  者:huangzh
/// 创建日期:2016-05-06 11:55:36
/// 任务编号:
/// </summary>
/// <param name="strTitle">strTitle</param>
public void SetTitle(string strTitle)
{
string strjsBlock = "<script>SetTitle('" + strTitle + "'); </script>"; m_page.Response.Write(strjsBlock);
m_page.Response.Flush();
} /// <summary>
/// 功能描述:设置进度
/// 作  者:huangzh
/// 创建日期:2016-05-06 11:55:45
/// 任务编号:
/// </summary>
/// <param name="percent">percent</param>
public void AddProgress(int intpercent)
{
ThisValue = ThisValue + intpercent;
double dblstep = ((double)ThisValue / (double)MaxValue) * ; string strjsBlock = "<script>SetPorgressBar('" + dblstep.ToString("0.00") + "'); </script>"; m_page.Response.Write(strjsBlock);
m_page.Response.Flush();
} public void DisponseProgress()
{
string strjsBlock = "<script>SetCompleted();</script>";
m_page.Response.Write(strjsBlock);
m_page.Response.Flush();
}
}
}

然后就是调用方法了,调用很简单,在页面的按钮事件或者其他什么地方加入代码,如在按钮事件里这么用

   protected void btnImport_Click(object sender, EventArgs e)
{
ProgressBar pb = new ProgressBar(this);
pb.SetMaxValue();
pb.InitProgress();
pb.SetTitle("这是一个测试数据");
for (int i = ; i <= ; i++)
{
pb.AddProgress();
//此处用线程休眠代替实际的操作,如加载数据等
System.Threading.Thread.Sleep();
}
pb.DisponseProgress();
}

怎么样,是不是很简单呢。

asp.net 的一个简单进度条功能的更多相关文章

  1. .Net Framework4.5中Asp.net mvc使用Singal R轮训实现导入进度条功能

    .Net Framework4.5中Asp.net mvc使用Singal R轮训实现导入进度条功能 我的项目需求是:在.net4.5中用mvc5实现上传xml文件,后台实时导入数据库时传到前台进度, ...

  2. wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合

    wpf 导出Excel   1 private void Button_Click_1(object sender, RoutedEventArgs e) 2 { 3 4 ExportDataGrid ...

  3. js 实现进度条功能。

    /** * 纯js进度条 * Created by kiner on 15/3/22. */ function progress(options){ this.w = (options &&a ...

  4. 一个Notification 进度条插件(android,NJS实现,直接就可使用)

    参考文章:http://ask.dcloud.net.cn/article/503 源码地址下载 如题,分享一个Notification 进度条插件(android,用js调用原生api实现,直接就可 ...

  5. php+javascript实现的动态显示服务器运行程序进度条功能示例

    本文实例讲述了php+javascript实现的动态显示服务器运行程序进度条功能.分享给大家供大家参考,具体如下: 经常有这样的业务要处理,服务器上有较多的业务需要处理,需要分批操作,于是就需要一个提 ...

  6. python基础-实现进度条功能,for和yield实现

    实现进度条功能 方法一:简单FOR实现打印进度条功能 for i in range(10): print("#",end="",flush=True) time ...

  7. jquery自带的进度条功能如何使用?

    弹出进度条:先做弹出的功能modal,再做进度条显示.在弹出的界面上增加进度条功能 $.ajax({ xhr: function() { var xhr = new window.XMLHttpReq ...

  8. Python实现进度条功能

    Python实现进度条功能 import sys, time def progress(percent, width=50): # 设置进度条的宽度 if percent >= 100: # 当 ...

  9. asp.net文件上传进度条研究

    文章:asp.net 文件上传进度条实现代码

随机推荐

  1. hdu Jungle Roads(最小生成树)

    Problem Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of for ...

  2. (c#)SKYPE API项目总结(一)

    原文:(c#)SKYPE API项目总结(一) 这个项目的需求:SKYPE软件文字聊天同步翻译,并将翻译后的内容会发送给对方,将对方发给自己的话翻译成自己语种.功能见图:               ...

  3. oracle_job 清空冗余数据 ,每一分钟执行一次

    参照这个例子:http://cherryqq.iteye.com/blog/855022 思路: data表中有4条数据 ,relation有3条数据,通过data_id 对应,需要定时删除 data ...

  4. LeetCode_算法及数据结构覆盖统计

    [输入]共计151道题的算法&数据结构基础数据 (见附录A) [输出-算法]其中有算法记录的共计 97道 ,统计后 结果如下  top3(递归,动态规划,回溯) 递归 动态规划 回溯 BFS ...

  5. Codeforces 328B-Sheldon and Ice Pieces(馋)

    B. Sheldon and Ice Pieces time limit per test 1 second memory limit per test 256 megabytes input sta ...

  6. 【百度地图API】小学生找哥哥——小学生没钱打车,所以此为公交查询功能

    原文:[百度地图API]小学生找哥哥--小学生没钱打车,所以此为公交查询功能 任务描述: 有位在魏公村附近上小学的小朋友,要去北京邮电大学找哥哥.他身上钱很少,只够坐公交的.所以,百度地图API快帮帮 ...

  7. AngularJS系列之总结

    AngularJS深入的系列就是这九篇博客了,把我以前在项目中应用到的和自己学习的都总结在了里面.为了更方便的看,把我写的AngularJS系列的博客都列到下面.之后就开始学习ionic:html5移 ...

  8. Android注入事件的三种方法比较

    方法1:使用内部APIs 该方法和其他所有内部没有向外正式公布的APIs一样存在它自己的风险.原理是通过获得WindowManager的一个实例来访问injectKeyEvent/injectPoin ...

  9. PL/SQL个人学习笔记(二)

    IF条件 declare cursor s is            select version from city_server t;   s_ city_server.version%type ...

  10. Java堆栈(转)

     Java栈与堆 ----对这两个概念的不明好久,最终找到一篇好文,拿来共享 1. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方.与C++不同,Java自己主动管理栈和堆, ...