我試圖設置一個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
@dotnetrob我從來沒有遇到過需要在另一個UpdatePanel中擁有'UpdatePanel'的場景。我的回答可能會有所幫助,但我認爲你應該考慮是否有更好的方法來處理這個問題,而不必在另一箇中嵌入一個。 – Kelsey 2010-08-18 00:25:54