简体   繁体   中英

How to refresh page using c# int every five minutes?

如何在ASP.NET中每五分钟使用c#刷新一次页面?

One is Javascript:

setTimeout("location.reload(true);", timeout);

The second is a Meta tag:

<meta http-equiv="refresh" content="300">

在标题中使用以下HTML元标记<META HTTP-EQUIV="REFRESH" CONTENT="300">应该做的伎俩

You can't force an HTML page to refresh from the server side. The client must request the page.

The only ways to do this always involve either using the META refresh tag, the Refresh HTTP header, or else javascript which forces a page reload on an interval.

Any "server-side" solution will do it by either writing javascript or the META tag to the page. There's simply no other way to do it.

the simplest way is

<Head>
<meta equiv="refresh" content="5">
</Head> 

or use timer control to refresh a webpage for every five minutes for example: drag and drop timer control in form.aspx and in form load add the code like below

<asp:Timer ID="Timer1" runat="server" Interval="6000" ontick="Timer1_Tick" />

form load

public void DoMagic()
{


}
protected void Timer1_Tick(object sender, EventArgs e)
{
DoMagic();
Label1.Text = "";
}
 window.setInterval(function () {
            // this will execute every 1 second

            methodCallOrAction();

        }, 1000);



function methodCallOrAction()
{
// u can call an url or do something here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM