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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
Forbes - Security
Forbes - Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Latest news
Latest news
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
Vercel News
Vercel News
V
Vulnerabilities – Threatpost
I
InfoQ
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
F
Full Disclosure
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
Hugging Face - Blog
Hugging Face - Blog
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Engineering at Meta
Engineering at Meta
The Register - Security
The Register - Security
T
Tor Project blog
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security Affairs
W
WeLiveSecurity
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Apple Machine Learning Research
Apple Machine Learning Research
H
Heimdal Security Blog
S
Secure Thoughts
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Latest
Security Latest
Martin Fowler
Martin Fowler
G
Google Developers Blog
宝玉的分享
宝玉的分享
腾讯CDC
TaoSecurity Blog
TaoSecurity Blog
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Project Zero
Project Zero
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog

博客园 - 赣江源

StreamInsight参考示例 Microsoft StreamInsight简介 GridView中的DataFormatString失效解决办法 - 赣江源 - 博客园 按照时间点还原数据库(SQL Server) 如何显示在线用户? ASP.NET中每个页面在Load之前调用公用函数 网站单点登录的实现思路 在服务器端提取ASP.NET控件输出的HTML 如何处理在IE7关闭时不出现选项卡提示 获取GridView单元格值的通用函数 如何在GridView将数字显示成金额格式或自定义格式? ASP.NET 2.0中使用XSLT的变化 在GridView表头显示排序方向 利用AJAX实现DropDownList与GridView做实时更新 输出时清除GridView的Style ASP.NET实现打印的方法小结 提高ASP.NET性能的一点方法 asp.net的一些小技巧 route命令详解
使用JavaScript控制UpdatePanel的更新
赣江源 · 2008-01-10 · via 博客园 - 赣江源

在 ASP.NET AJAX 机制下,使用 UpdatePanel 控件有很好的用户体验,它可以让开发人员不用编写繁杂的 javascipt相关程序代码,就能享有 AJAX 的效果。一般包含在 UpdatePanel 中的子控件,如果子控件有执行 PostBack 操作时,UpdatePanel 的机制在前端会拦截 __doPostBack 操作,使得控件产生的 PostBack 都会经由 UpdatePanel 统一处理,以做到局部更新的效果。

可是有时候我们会需要透过 JavaScript 要求 UpdatePanel 做更新的操作,一般都会以为直接呼叫 __doPostBack 即可。

以一个实例来做测试,我们在页面的 UpdatePanel 放置一个 Label 来显示最新时间。然后通过HTML控件 Input (type=button) 在 onclick 直接调用 __doPostBack 事件函数。

        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        
<div>
            
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
                
<ContentTemplate>
                    Server Time:
                    
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                
</ContentTemplate>
            
</asp:UpdatePanel>
            
<input id="Button1" type="button" value="button" onclick="__doPostBack('','');" />
        
</div>

protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text 
= System.DateTime.Now.ToString();
    }

以上程序的实际执行并不如预期的那样,UpdatePanel 中的时间是更新了,但是页面却会有闪烁的效果,这个 PostBack 并没有受到 UpdatePanel 的控制。

经过后来的多次的测试后发现,其实只要做一点修改就可以达到页面不闪烁的效果,就是在 __doPostBack 函数的第一个参数 (eventTarget),传入 UpdatePanel 的 ClientID 即可。如下:

<input id="Button1" type="button" value="button" onclick="__doPostBack('UpdatePanel1','');" />