Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timer in UpdatePanel

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!!

like image 815
LilMoke Avatar asked Aug 19 '10 15:08

LilMoke


People also ask

What is timer control in asp net?

The ASP.NET AJAX Timer control performs postbacks at defined intervals. If you use the Timer control with an UpdatePanel control, you can enable partial-page updates at a defined interval. You can also use the Timer control to post the whole page.

What is timer control in Ajax?

The AJAX Timer control enables a portion of an ASP.NET web page to be dynamically updated at a regular interval, rather than needing the user to perform an action such as clicking on a button.

What is AJAX explain Timer control and UpdatePanel control with suitable example?

Ajax (Asynchronous JavaScript and XML) is a new web development technique for the interactive websites. With AJAX to help we can develop web applications and retrieve small amounts of data from a web server. AJAX consists of a different type of technology. Timer controls allow you to do postbacks at certain intervals.

What is trigger in UpdatePanel?

Triggers for a given UpdatePanel, by default, automatically include any child controls that invoke a postback, including (for example) TextBox controls that have their AutoPostBack property set to true.


1 Answers

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.

like image 111
Kelsey Avatar answered Sep 21 '22 00:09

Kelsey