UpdatePanel中的计时器

Lil*_*oke 6 c# asp.net updatepanel master-pages timer

我有一个带有asp:Timer的asp:UpdatePanel.它们位于主/内容页面中.代码如下:

<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>
Run Code Online (Sandbox Code Playgroud)

但是当计时器触发时,我得到以下错误:

Microsoft JScript运行时错误:Sys.WebForms.PageRequestManagerParserErrorException:无法解析从服务器收到的消息.此错误的常见原因是通过调用Response.Write(),响应过滤器,HttpModules或服务器跟踪来修改响应.详细信息:解析附近时出错

这适用于独立的Web表单,但不适用于具有母版页的内容页面.

任何人都可以解释这个问题吗?

在此先感谢您的帮助!!

Kel*_*sey 9

是否有一个特定的理由为什么你有Timer控制权UpdatePanel

每次我需要使用一个Timer控件来进行UpdatePanel刷新时,我都将其设置为如下所示,它可以正常工作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> 
Run Code Online (Sandbox Code Playgroud)

使用Trigger以使事件UpdatePanel刷新Tick.您只想在UpdatePanel可能的情况下嵌入内容.