如何每两分钟自动刷新页面? [英] How To Autorefresh A Page Every Two Minutes?

查看:186
本文介绍了如何每两分钟自动刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我..


如何每两分钟自动刷新页面?

can any one help me..


How To Autorefresh A Page Every Two Minutes?

推荐答案

可以通过添加一些HTML代码在ASP.NET(.aspx)网页中实现自动网页刷新.在标题部分.
您只需在标题"部分中添加以下代码行即可在ASP.NET网页中启用自动刷新.
Automatic web page refresh can be implemented in an ASP.NET (.aspx) web-page by adding some HTML code in the header section.
You can simply add following line of code in the Header section to enable auto refresh in an ASP.NET web page.
<meta http-equiv="refresh" content="120">


其中120是指刷新页面之前需要花费的秒数.
另外,如果您将URL放在标记内,也可以重定向到特定页面.


Where 120 refers to the number of seconds it will take before refreshing the page.
Also you can redirect to a specific page if you put the URL inside the tag.

<meta http-equiv="refresh" content="15;url=http://www.portinggurus.com">


实际上,这是标准的HTML功能,并且不特定于ASP.NET.无论是ASP.NET页面还是HTML页面,还是用Java,PHP,ColdFusion,Perl等制成的页面,都可以看到自动刷新的相同效果.
如果要动态设置刷新时间,则可以在ASP.NET中通过在Page_Load函数中添加服务器端代码来设置刷新时间来进​​行设置,如下所示:


In reality, this is standard HTML functionality and nothing specific to ASP.NET. The same effect of auto-refresh would be seen whether it is an ASP.NET page or just a HTML page, or a page made in Java, PHP, ColdFusion, Perl or the like.
If you want to set the refresh time dynamically then that can be done in ASP.NET by adding server side code in the Page_Load function to set it, as shown below:

Response.AppendHeader("Refresh", "120")


在此处获得带有源代码的良好示例:
自动刷新网页 [


Get a good example with source code here:
Auto Refresh Web Page[^]


上面的解决方案是最简单的,但这不是优雅的.此代码将要求浏览器刷新所有内容,这会使您的页面闪烁(闪烁).更专业,更美观的方法是使用两个内置控件-更新面板计时器.

只需将要更新的控件拖放到更新面板"上,您将得到类似的内容.

The solution above is the simplest, but it is not the elegant one. This code would require browser to refresh everything which will make your page flashing (blinking). More professional and better-looking approach is to use two built-in controls - Update Panel and Timer.

Simply drag and drop controls you want to update onto Update Panel and you will have something like that.

<asp:updatepanel id="UpdatePanel1" runat="server" xmlns:asp="#unknown">
   <contenttemplate>
      <asp:label id="UpdateLabel1" runat="server"></asp:label>
      <asp:gridview id="UpdateGridView1" runat="server"></asp:gridview>
      <asp:timer id="Timer1" runat="server"></asp:timer>
   </contenttemplate>
   <triggers>
   </triggers>
</asp:updatepanel>



计时器控制基于称为滴答"的时间间隔,在用户指定的时间(以毫秒为单位)之后,它将午餐Tick()事件.为了您的目的,将Timer属性的Interval设置为120000,这相当于120秒.在tick事件中,编写所有数据分配代码,例如:



Timer control is based on time intervals called Ticks, which after time specified by user (in milliseconds) will lunch Tick() event. For your purpose set Timer property Interval for 120000, which is equivalent of 120 seconds. Inside tick event write all your data assignment code, for example:

protected void Timer1_Tick(object sender, EventArgs e)
{
  //read data from SQL or file 
  Label1.Text = SomeString;
  GridView1.DataSource = DataSet;
  GridView1.DataBind();
}



要使页面组件自动刷新,您需要设置触发器.单击以获取触发器集合,添加新的 AsyncPostBack 触发器,并在行为部分中将 Timer1 设置为 ControlID . b>和 EventName 表示 Tick .



To make your page components autorefresh you will need to set Trigger. Click for Triggers collection, add new AsyncPostBack trigger and in Behavior section set ControlID for Timer1 and EventName for Tick.


这篇关于如何每两分钟自动刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆