首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >更新子UpdatePanel中的父UpdatePanel -有条件

更新子UpdatePanel中的父UpdatePanel -有条件
EN

Stack Overflow用户
提问于 2010-08-18 03:23:21
回答 2查看 1.7K关注 0票数 0

我试图设置一个updatepanel来每X秒更新一次,问题是我不想让控件真正刷新,除非有新的数据。所以我现在在父updatepanel中有一个子UpdatePanel,这个子updatepanel会被一个定时器刷新。但我似乎找不到一种方法来触发父面板进行更新。同样,仅当满足特定条件(数据已更改)时。

示例代码:

代码语言:javascript
运行
复制
<asp:Timer ID="Timer1" OnTick="Timer1_Tick" runat="server" Interval="10000"></asp:Timer>
<asp:updatepanel id="upParent" runat="server" UpdateMode="Conditional">
    <ContentTemplate>    
        <asp:Label id="lblParenttime" Runat="server">Parent Time Here</asp:Label>     
        <asp:updatepanel id="upChild" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Label id="lblChildtime" Runat="server">Child Time Here</asp:Label>
            </ContentTemplate>
            <triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </triggers> 
        </asp:updatepanel>  
    </ContentTemplate>
</asp:updatepanel>  

Protected Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
   lblChildtime.Text = Now.Tostring
   if X = Y then
       'Cause Parent to Update
       lblParenttime.Text = Now.Tostring
   end if     
End Sub
EN

回答 2

Stack Overflow用户

发布于 2010-08-18 05:31:37

当您使用以下javascript代码进行UpdatePanel刷新时,可以触发一些javascript:

代码语言:javascript
运行
复制
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(YourJavascriptFunctionNameHere);

然后,您可以在另一个UpdatePanel上放置一个隐藏按钮,并从挂接到UpdatePanel重新加载的javascript函数中手动调用__DoPostBack

关于如何在您的场景中利用add_pageLoaded,可能还有其他想法,但这至少应该让您走上正确的道路。

票数 0
EN

Stack Overflow用户

发布于 2011-06-10 15:52:30

当满足条件时,您是否尝试过在Timer1_Tick事件中使用upParent.Update()

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3506132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档