UpdatePanel 中的计时器会导致某种完全回发

发布于 2024-12-20 14:22:45 字数 1003 浏览 4 评论 0原文

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

我在此页面上还有一个调用数据库并从中检索数据的函数。该函数不会从更新面板调用,甚至不会与其相关。

问题是我在日志文件中看到,每次有一个勾号并且更新面板被更新时,还会调用我的数据库服务器(此函数位于 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 中。

感谢任何帮助,

谢谢

多伦

I have some sort of a strange problem, I have an update panel which is triggerd by a timer.

Also I have on this page is a function that calls the DB and retrieves data from it. the function does not being called from the update panel or even related to it.

the problem is that I see in my log file that every time there is a tick and the update panel being updated there is also a call to my DB server (this function is in the page_Load section ) to retrieve the data again. but the page doesn't seem to do a full postback (It stays the same and doesn't looks like being reloaded)

my code:

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

and code behind:

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);
}

The function to retrieve data from the DB is in the page_load of the page.

Any help is appreciated

Thank you

Doron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兮子 2024-12-27 14:22:45

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

转到此链接部分页面呈现

并滚动到部分背景。

Using the Update panel doesn't refresh whole page, only controls inside update panel, but when Partial Update is executed all the server page life-cycle events occur, and view-state and form data are preserved, but when rendering page only part of update panel is rendered and returned to user.

Go to this link Partial page rendering

and scroll to the section background.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文