Update Parent UpdatePanel from Child UpdatePanel - Conditionally
I am trying to trying to setup an updatepanel to update every X seconds, the problem is I don't want the control to actually refresh unless there is new data. So I currently have a child updatepanel in a parent UpdatePanel, the child updatepanel gets refreshed by a timer. But I can't seem to find a way to trigger the parent panel to update. Again, only when certain conditions(data changed) are met.
Sample Code:开发者_Python百科
<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
You can trigger some javascript when you UpdatePanel
refreshes with the following javascript code:
var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(YourJavascriptFunctionNameHere);
You could then put a hidden button on the other UpdatePanel
and manually call the __DoPostBack
from the javascript function you have hooked onto the UpdatePanel
reload.
There is probably other ideas for how to leverage add_pageLoaded
in your scenario but this should at least get you on the right track.
Have you tried upParent.Update()
in the Timer1_Tick event when conditions are met ?
精彩评论