All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
结合ASP.NET与javascript开发电子沙盘_.net资料_编程技术
在SQL Server2005中还原数据库_[SQL Server教程]
在asp.net2.0页面部分缓存中使用PartialCachingAttribu
LAMP-Linux+Apache+Mysql+PHP典型配置_php资料_编程技术
Flex与asp.net的WebService通讯_.net资料_编程技术
asp.net教程-返回前一页实现方法总结_[Asp.Net教程]
Delphi菜单动态合并实例
ASPX文件转HTML_[Asp.Net教程]
数据库正规化和设计技巧(2)_mssql学习_编程技术
SQL中CASE使用_mssql学习_编程技术
Reading number is top 10 pictures
真正的国产-非模拍 贵在是真实2
Take you to walk into the most true north Korea rural3
西方气质的东方美女2
中国文革时期的色情图片2
50个至今影响世界的德国发明
The real super beauty8
Kim jong il's mistress, national beauty JinYuJi actor3
Group of female porn in 《westwards》, uninhibited woman threatened to not the bottom line2
The terra-cotta warriors3
Discharge accidentally Actresses by the breast4
Download software ranking
传奇私服架设教程
Dance with duck(male prostitution)
ASP.NET.2.0.XML.高级编程(第3版)
asp.netWeb服务器高级编程
Unix video tutorial18
Boxer's Top ten classic battle5
Unix video tutorial14
Kung fu panda - the secret of the teacher
Macromedia Dreamweaver 8
Unix video tutorial9
delv published in(发表于) 2014/1/6 9:04:10 Edit(编辑)
ASP.NET技巧:教你制做Web实时进度条_[Asp.Net教程]

ASP.NET技巧:教你制做Web实时进度条_[Asp.Net教程]

ASP.NET技巧:教你制做Web实时进度条_[Asp.Net教程]























网上已经有很多Web进度条的例子,但是很多都是估算时间,不能正真反应任务的真实进度。我自己结合多线程和ShowModalDialog制做了一个实时进度条,原理很简单:使用线程开始长时间的任务,定义一个Session,当任务进行到不同的阶段改变Session的值,线程开始的同时使用ShowModalDialog打开一个进度条窗口,不断刷新这个窗口获取Session值,反应出实时的进度。下面就来看看具体的代码:(文章结尾处下载源代码)




先新建一个Default.aspx页面,
客户端代码:













服务器端代码:
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 description for _Default.
///

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

/**////


/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);




}
#endregion




private void LongTask()
{
//模拟长时间任务
//每个循环模拟任务进行到不同的阶段
for(int i=0;i<11;i++)
{
System.Threading.Thread.Sleep(1000);
//设置每个阶段的state值,用来显示当前的进度
Session["State"] = i+1;
}
//任务结束
Session["State"] = 100;




}




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




sbScript.Append("\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);
}
}
}





新建一个进度条页面Progress.aspx
客户端:
在head中加入



ForeColor="Silver">





服务器端:
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 description for Progress.
///

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("","");
}
if(state==100)
{
this.panelProgress.Visible = false;
this.panelBarSide.Visible = false;
this.lblMessages.Text = "Task Completed!";
Page.RegisterStartupScript("","");
}
}




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

/**////


/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);




}
#endregion
}
}




来源:网络












































添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.