I'm tacking on some additional functionality to an ASP.NET Web Forms site.

The master page has a Literal inside an UpdatePanel that gets populated with some text on a timer interval.

I needed to also display the same text in another Literal inside an UpdatePanel on a web form page.

So I added an event to the master page, subscribe to that event on the web form page, and attempt to update both UpdatePanels at the same time with .Update().

Unfortunately, no matter what I have tried so far, the master page updates but the web form page does not. If I debug, I see it execute each .Update() but the web form page does not update, even if I change the order.

This leads me to the conclusion that there is some issue with updating multiple UpdatePanels in different files. Except I have a similar scenario (one in master page, one in user control added to master page) that works.

How can I do what I want to do?

Here's my master page markup:

<asp:UpdatePanel ID="upnlNotifications" runat="server" UpdateMode="Conditional" RenderMode="Inline">
    <ContentTemplate>
        <asp:Timer ID="tmrNotifications" runat="server" Interval="300000" OnTick="tmrNotifications_Tick"></asp:Timer>
        <asp:Literal ID="ltlNotifications" runat="server"></asp:Literal>
    </ContentTemplate>
</asp:UpdatePanel>

And the code-behind:

public event EventHandler NotificationsUpdated;

protected void tmrNotifications_Tick(object sender, EventArgs e)
{
    ltlNotifications.Text = "updated";

    if (NotificationsUpdated != null)
    {
        NotificationsUpdated(this, EventArgs.Empty);
    }

    upnlNotifications.Update();
}

And here's my web form page markup:

<asp:UpdatePanel ID="upnlNotifications" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Literal ID="litNotifications" runat="server"></asp:Literal>
    </ContentTemplate>
</asp:UpdatePanel>

And the code-behind:

protected void Page_Init(object sender, EventArgs e)
{
    ((Site)Page.Master).NotificationsUpdated += NotificationsUpdated;
}

protected void NotificationsUpdated(object sender, EventArgs e)
{
    ltlNotifications.Text = ((Literal)((Site)Page.Master).FindControl("ltlNotifications")).Text;

    upnlNotifications.Update();
}

Related posts

Recent Viewed