2010-08-17 78 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()