Timer in UpdatePanel
Asked Answered
M

1

6

I have an asp:UpdatePanel with an asp:Timer. These are in a Master/Content Page. The code is below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick"></asp:Timer>
    </ContentTemplate>
</asp:UpdatePanel>

But when the timer fires, I get the folowing error:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. Details: Error parsing near '

This works in a standalone web form, but not in a content page with a master page.

Can anyone explain a fix for this?

Thanks in advance for any help!!

Megalocardia answered 19/8, 2010 at 15:36 Comment(0)
S
11

Is there a specifc reason why you have the Timer control in the UpdatePanel?

Every time I have needed to use a Timer control to cause an UpdatePanel refresh, I have set it up like the following and it works fine with MasterPages:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
    <Triggers>
        <asp:AsyncPostBackTrigger  ControlID="Timer1" EventName="Tick" />
    </Triggers>
    <ContentTemplate> 
        <!-- your content here, no timer -->
    </ContentTemplate> 
</asp:UpdatePanel> 

<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick">
</asp:Timer> 

Use the Trigger to cause the UpdatePanel to refresh from the Tick event. You only want to embed content in your UpdatePanel if possible.

Schoolboy answered 19/8, 2010 at 15:45 Comment(1)
Actually, I had that exact code and it was not working either... BUT, you made me look elsewhere, and I relaized I had this in my PageLoad: Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore(); And that appears to be the problem... commented those out and it works perfectly. Thank you your info.Megalocardia

© 2022 - 2024 — McMap. All rights reserved.