【问题标题】:Timer in UpdatePanel causes some sort of full postbackUpdatePanel 中的计时器导致某种完整的回发
【发布时间】:2011-12-09 19:25:15
【问题描述】:

我有一个奇怪的问题,我有一个由计时器触发的更新面板。

我在这个页面上还有一个函数,它调用数据库并从中检索数据。该函数没有被更新面板调用,甚至没有与之相关。

问题是我在我的日志文件中看到,每次出现打勾并且更新面板正在更新时,还会调用我的数据库服务器(此函数在 page_Load 部分中)以再次检索数据。但是该页面似乎没有进行完整的回发(它保持不变并且看起来不像被重新加载)

我的代码:

<asp:Timer runat="server" id="UpdateTimer" interval="5000" ontick="UpdateTimer_Tick" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
    </Triggers>
    <ContentTemplate>
        <span id="s1" runat="server"></span>
    </ContentTemplate>
</asp:UpdatePanel>  

和后面的代码:

protected void UpdateTimer_Tick(object sender, EventArgs e)
{
    DateTime dt = TimeConvertor.getCurrentGameTime();
    s1.InnerText = String.Format("Current game time: {0:dd/MM/yyyy HH:mm}", dt);
}

从数据库中检索数据的函数在页面的page_load中。

感谢任何帮助

谢谢

多伦

【问题讨论】:

  • 设置InnerText后,尝试调用UpdatePanel1.Update()

标签: c# timer updatepanel postback


【解决方案1】:

使用更新面板不会刷新整个页面,只在更新面板内部进行控制,但是当执行部分更新时,所有服务器页面生命周期事件都会发生,并且会保留视图状态和表单数据,但是在渲染页面时只有更新面板的一部分被渲染并返回给用户。

转到此链接Partial page rendering

并滚动到部分背景。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-21
  • 1970-01-01
  • 2010-10-30
  • 1970-01-01
  • 2010-10-23
  • 2011-08-04
相关资源
最近更新 更多