惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

爱范儿
爱范儿
V
Vulnerabilities – Threatpost
B
Blog
月光博客
月光博客
宝玉的分享
宝玉的分享
有赞技术团队
有赞技术团队
美团技术团队
IT之家
IT之家
B
Blog RSS Feed
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
Vercel News
Vercel News
Jina AI
Jina AI
Y
Y Combinator Blog
Recorded Future
Recorded Future
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
L
LangChain Blog
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
Schneier on Security
Schneier on Security
Microsoft Azure Blog
Microsoft Azure Blog
P
Privacy International News Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
N
News and Events Feed by Topic
W
WeLiveSecurity
L
Lohrmann on Cybersecurity
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
P
Proofpoint News Feed
S
Schneier on Security
Last Week in AI
Last Week in AI
L
LINUX DO - 最新话题
Webroot Blog
Webroot Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
云风的 BLOG
云风的 BLOG
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks
T
Threatpost
腾讯CDC
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
The Exploit Database - CXSecurity.com
H
Help Net Security

博客园 - 谭洪星

NHibernate教程(转载) MVC模式在.NET框架中的应用与实现 混乱的MVC,.NET非要MVC不可么?(转) ASP.NET实现URL映射 PetShop的系统架构设计(转) ASP.NET中常用的优化性能方法 设计模式学习笔记(三)——Abstract Factory抽象工厂模式 (转) 观察者模式及实现(转) 悟透JavaScript (转) 深入研究Asp.net页面的生命周期 [你必须知道的.NET] 第一回:恩怨情仇:is和as Net中的反射使用入门 .Net 中的反射(反射特性) - Part.3 .net反射简介 软件工程心理学之---让客户知错,但不能向你发怒 C#(也适用其他)的初学者对string是值类型还是引用类型搞不清楚,还有对参数传递也比较迷糊 C#泛型之详解 [你必须知道的.NET]第十二回:参数之惑---传递的艺术(下) [你必须知道的.NET]第十一回:参数之惑---传递的艺术(上)
用AJAX.NET的客户端脚本实现UpdateProgress的效果 - 谭洪星 - 博客园
谭洪星 · 2008-05-28 · via 博客园 - 谭洪星

用过ajax.net框架里的updatePanel的用户肯定会知道updateprogress的作用,专门用来在执行异步操作显示等待信息,用法非常简单,往里面放一些图片或文字即可实现看起来很不错的效果。但是这种方式是在页面运行之前就已经设置好了,不管什么操作都显示同一张图片或者文字,不能针对某个具体的按钮或者发送对象来显示信息,比如针对保存操作就显示"保存中...",提交操作就显示"提交中...",也就是能通过编程方式稍微灵活控制一下。也许有人说可以多设置几个updatepanel,给每个updatepanel分配一个updateProgress,这也是种方法,但是生成的标记未免多了点。
最近看了一下AJAX.NET的客户端脚本文档,知道通过框架提供的脚本能够更加细微的控制要显示的内容,并且还可以加上"取消"按钮或连接,点击取消可停止asyncPostback。通过脚本实现需要自己定制个类似updateProgress的div或者span,另外还要添加页面事件,控制提示信息的可见性。主要用到的是客户端脚本里的页面事件,具体简单实现如下:


 1<script language="javascript" type="text/javascript">
 2    function pageLoad()
 3    {
 4        // 添加事件
 5        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(onBeginRequest);
 6        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(onEndRequest);   
 7    }

 8    
 9    function onBeginRequest(sender, e)
10    {
11        var elem = e.get_postBackElement();
12        var requestManager = Sys.WebForms.PageRequestManager.getInstance(); 
13        
14        // 点击取消则停止 
15        if (requestManager.get_isInAsyncPostBack() & elem.id == "btnCancel" )
16        {
17             requestManager.abortPostBack();
18        }

19        
20        // 显示正在处理的信息 
21        if (elem.id != "btnCancel")
22        {  
23            dispUpdateProgress(String.format("{0} oper is processing.", elem.value), "");
24        }
 
25    }

26    
27    function onEndRequest(sender, e)
28    {
29        dispUpdateProgress("""none");
30    }

31    
32    //  控制显示提示信息
33    function dispUpdateProgress(msg, display)
34    {
35        $get("updateProgress").style.display = display;
36        $get("processingMsg").innerHTML = msg;
37    }

38    </script>
39 <form id="form1" runat="server">
40        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>
41    <asp:UpdatePanel ID="up" runat="server">
42    <ContentTemplate>
43    <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />&nbsp;&nbsp;
44    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSave_Click" />
45    <div id="updateProgress" style="display:none">
46    <span id="processingMsg"></span>
47    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
48    </div>
49    </ContentTemplate>
50    </asp:UpdatePanel> 
51    </form>


1protected void btnSave_Click(object sender, EventArgs e)
2        {
3            Thread.Sleep(4000);
4        }