2010-08-17 57 views
0

我试图设置一个updatepanel更新每隔X秒,问题是我不希望控件实际刷新,除非有新数据。所以我现在有一个父UpdatePanel中的子更新面板,子更新面板被定时器刷新。但我似乎无法找到触发父面板更​​新的方法。同样,只有当某些条件(数据已更改)得到满足时。从子UpdatePanel更新父UpdatePanel - 有条件

示例代码:

<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 
+0

@dotnetrob我从来没有遇到过需要在另一个UpdatePanel中拥有'UpdatePanel'的场景。我的回答可能会有所帮助,但我认为你应该考虑是否有更好的方法来处理这个问题,而不必在另一个中嵌入一个。 – Kelsey 2010-08-18 00:25:54

回答

0

您可以触发一些javascript,当你UpdatePanel与下面的JavaScript代码刷新:

var prm = Sys.WebForms.PageRequestManager.getInstance(); 
prm.add_pageLoaded(YourJavascriptFunctionNameHere); 

然后你可以把在其他UpdatePanel一个隐藏的按钮和手动调用来自javascript函数的__DoPostBack已挂钩到UpdatePanel重新加载。

可能还有其他方法可以帮助您在场景中利用add_pageLoaded,但这至少可以帮助您走上正轨。

0

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