最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - How can I have an ascx postback and refresh itself automatically every X seconds? - Stack Overflow

programmeradmin6浏览0评论

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.

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.

Share Improve this question edited Nov 13, 2009 at 23:54 Kelsey 47.8k16 gold badges127 silver badges162 bronze badges asked Nov 13, 2009 at 23:30 MattMatt 27k67 gold badges202 silver badges317 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

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.

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.

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);
发布评论

评论列表(0)

  1. 暂无评论