CODEDIGEST
Home Articles CodeDigest Tutorials FAQs
Home > CodeDigest >  
Technologies
 


Programmatically refresh an aspx page at equal interval from CodeBehind using C# and ASP.Net
Submitted By Satheesh Babu B
On 3/2/2010 8:05:41 AM
Tags: ASP.Net,CodeDigest  

Programmatically refresh an aspx page at equal interval from CodeBehind using C# and ASP.Net

 

We can refresh a webpage with the help of meta tags at regular intervals. When we place the below meta tag in head tag, it will refresh your webpage automatically every 100 seconds.
<meta http-equiv="refresh" content="100">

 

At times, we might want to conditionally refresh an ASPX page automatically from codebehind file.
With the introduction of ASP.Net 2.0, we can set Meta tags dynamically from codebehind class using HtmlMeta class.

 

To refresh our aspx page from the codebehind class we can use the following code,

 

public void RefreshPage()
    {
HtmlMeta meta = new HtmlMeta();
HtmlHead head = (HtmlHead)Page.Header;
meta.HttpEquiv = "refresh";
meta.Content = "5";
head.Controls.Add(meta);
}

 

The above code will emit appropriate meta tags similar to above to refresh the page automatically every 5 seconds.

 

Happy Coding!!

Recent Codes
  • View All Codes..