如何让 ascx 回发并每 X 秒自动刷新一次?

发布于 2024-08-11 03:23:24 字数 89 浏览 3 评论 0原文

我有一个 ascx 控件绑定到一个数据源经常更改的数据。有没有一种快速方法可以让 ascx 控制回发、重新绑定并每 X 秒刷新一次。 ascx 控件位于更新面板中。

I have an ascx control bound to a datasource with frequently changing data. Is there a quick way to have an ascx control postback, rebind and refresh itself every X seconds. The ascx control is in an update panel.

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

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

发布评论

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

评论(3

少跟Wǒ拽 2024-08-18 03:23:24

使用 AJAX 工具包中的计时器控件,因为您已经在使用它:

<asp:Timer ID="tmrPolling" runat="server" Interval="10000" ontick="tmrPolling_Tick"></asp:Timer>

向更新面板添加触发器,如下所示:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="tmrPolling" EventName="Tick" />
</Triggers>

然后只需实现 tmrPolling_Tick 处理程序:

protected void tmrPolling_Tick(object sender, EventArgs e)
{
    // Change your update panel controls and data here.
}

不要在更新面板内容区域中添加计时器。

Use a timer control from the AJAX toolkit since you are already using it:

<asp:Timer ID="tmrPolling" runat="server" Interval="10000" ontick="tmrPolling_Tick"></asp:Timer>

Add a trigger to your update panel like:

<Triggers>
    <asp:AsyncPostBackTrigger ControlID="tmrPolling" EventName="Tick" />
</Triggers>

Then just implement the tmrPolling_Tick handler:

protected void tmrPolling_Tick(object sender, EventArgs e)
{
    // Change your update panel controls and data here.
}

Do not add the timer within your update panel content area.

梦醒时光 2024-08-18 03:23:24

在客户端脚本中,您可以创建一个计时器并调用 __doPostBack() 来强制刷新更新面板。请查看本文了解详细信息

In a client script, you can create a timer and call __doPostBack() to force the update panel to refresh. Please see this article for details.

别再吹冷风 2024-08-18 03:23:24

为了清晰/懒惰而保留代码的重复。

function pageLoad(sender, args) 
{
   setTimeout(refreshPanel, 5000); // 5 seconds  
}

function requestEnd(sender, args)
{
   // Check for AJAX request errors if you'd like
   setTimeout(refreshPanel, 5000); // 5 seconds
}

function refreshPanel()
{
   __doPostBack('UpdatePanelIDHere', '');"
}

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(requestEnd);

Repetition of code maintained for clarity/laziness.

function pageLoad(sender, args) 
{
   setTimeout(refreshPanel, 5000); // 5 seconds  
}

function requestEnd(sender, args)
{
   // Check for AJAX request errors if you'd like
   setTimeout(refreshPanel, 5000); // 5 seconds
}

function refreshPanel()
{
   __doPostBack('UpdatePanelIDHere', '');"
}

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