【问题标题】:Timer in UpdatePanelUpdatePanel 中的计时器
【发布时间】:2010-08-19 15:36:25
【问题描述】:

我有一个带有 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>

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

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

这适用于独立的网络表单,但不适用于带有母版页的内容页面。

谁能解释一下解决方法?

提前感谢您的帮助!

【问题讨论】:

    标签: c# asp.net updatepanel timer master-pages


    【解决方案1】:

    UpdatePanel 中有Timer 控件是否有具体原因?

    每次我需要使用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> 
    

    使用Trigger 使UpdatePanelTick 事件刷新。如果可能,您只想在 UpdatePanel 中嵌入内容。

    【讨论】:

    • 实际上,我有那个确切的代码,但它也不起作用......但是,你让我在别处寻找,我在我的 PageLoad 中有这个:Response.Cache.SetExpires(DateTime. UtcNow.AddMinutes(-1)); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetNoStore();这似乎是问题所在……将这些注释掉了,并且效果很好。谢谢你的信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多