我有一个带有 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 或启用服务器跟踪来修改响应。 详细信息:在 ' 附近解析时出错
这适用于独立的 Web 表单,但不适用于具有母版页的内容页面。
谁能解释一下这个问题的解决方法?
在此先感谢您的帮助!
最佳答案
在 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
使 UpdatePanel
从 Tick
事件中刷新。如果可能,您只想在 UpdatePanel
中嵌入内容。
关于c# - 更新面板中的计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3523470/