Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Automatic Page Refresh in ASP.NET

0.00/5 (No votes)
10 Aug 2013 1  
How to do automatic page refresh in ASP.NET

Introduction

The web page that is displayed when you type a URL, for example, http://www.codeproject.com/ is in response to the request sent to the web server. It uses HTTP (Hypertext Transfer Protocol) to transfer data between a client (a web browser) and a server. Any request sent to a web server is processed at the web server and a response is sent to the client. For example, when the user clicks on a Submit button, data is sent to the web server as a request, the server processes the request and sends the response. The process is triggered by the user to send the request.

But in some situations, we may require to refresh a page automatically at a pre-defined time interval. This might not be recommended when you are using latest technologies like AJAX, but some developers might need to do this.

Using HTML META Tag

We can achieve this using the META tag as shown below (where Dashboard.aspx is the page that needs to be refreshed):

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

<meta http-equiv="refresh" content="30;url=Dashboard.aspx">  

Using ASP.NET, C# and MasterPages

These days, using Master Pages is common in many ASP.NET projects. If you use the META tag in this case, then all pages that use this master page will be refreshed, which is not desired. To accomplish this, add the following C# code in the code-behind page of the particular page you want to refresh (for example, Dashboard.aspx):

Response.AppendHeader("Refresh", 30 + "; URL=Dashboard.aspx");   

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here