我试图设置一个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