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

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
Jina AI
Jina AI
N
Netflix TechBlog - Medium
GbyAI
GbyAI
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
I
Intezer
T
Tor Project blog
P
Palo Alto Networks Blog
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
Cloudbric
Cloudbric
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
Forbes - Security
Forbes - Security
Last Week in AI
Last Week in AI
S
Security Affairs
博客园 - Franky
F
Fortinet All Blogs
量子位
M
MIT News - Artificial intelligence
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
S
Secure Thoughts
V
Visual Studio Blog
AI
AI
美团技术团队
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
T
Threatpost
Cyberwarzone
Cyberwarzone

博客园 - 赣江源

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','');" />