• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Asp.net基于ajax和jquery-ui实现进度条

asp 搞代码 4年前 (2022-01-03) 24次浏览 已收录 0个评论

这篇文章主要介绍了Asp.net基于ajax和jquery-ui实现进度条,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

  前台用ajax不来源gaodaimacom搞#^代%!码网停进行查询,直到任务完成。进度条用的是jquery-ui。后台用一般处理程序处理相应,进度信息保存在HttpContext.Application中。

  代码作为简单示例,实际应用时应对资源释放、防止多线程混乱等做进一步控制。

效果图:

  

代码:

前台:

   <title></title> <div> <label id="progress"></label><div id="progressbar"></div></div>

后台:

 // 2015年12月16日 09:53:11 // David Huang // 进度条示例 namespace ProgressTest { using System; using System.Threading; using System.Web; /// <summary> /// Handler1 的摘要说明 /// </summary> public class Handler1 : IHttpHandler { // context private HttpContext context; public bool IsReusable { get { return false; } } public void ProcessRequest(HttpContext context) { this.context = context; if (context.Request["RequestType"] == "AjaxRequest") { if (context.Request["Method"] == "GetProgress") { context.Response.Clear(); context.Response.Write(this.GetProgress()); context.Response.End(); } else { this.DoWork(); } } } /// <summary> /// 开始工作 /// </summary> private void DoWork() { for (int i = 0; i <100; i++) { // 记录进度 // 实际应用中需要进一步控制(利用用户信息、cookies等),防止并发造成混乱 this.context.Application["progress"] = i + 1; Random r = new Random(); Thread.Sleep(r.Next(10, 100)); } // 完成后释放资源 this.context.Application["progress"] = null; } /// <summary> /// 查询进度 /// </summary> /// 进度 private int GetProgress() { if (this.context.Application["progress"] != null) { return (int)this.context.Application["progress"]; } else { return -1; } } } }

以上就是Asp.net基于ajax和jquery-ui实现进度条的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Asp.net基于ajax和jquery-ui实现进度条

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址