我试图设置一个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发布于 2010-08-18 05:31:37
当您使用以下javascript代码进行UpdatePanel刷新时,可以触发一些javascript:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(YourJavascriptFunctionNameHere);然后,您可以在另一个UpdatePanel上放置一个隐藏按钮,并从挂接到UpdatePanel重新加载的javascript函数中手动调用__DoPostBack。
关于如何在您的场景中利用add_pageLoaded,可能还有其他想法,但这至少应该让您走上正确的道路。
发布于 2011-06-10 15:52:30
当满足条件时,您是否尝试过在Timer1_Tick事件中使用upParent.Update()?
https://stackoverflow.com/questions/3506132
复制相似问题