Click here to Skip to main content
15,884,773 members
Articles / Web Development / HTML
Tip/Trick

Automatic Page Refresh in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.32/5 (9 votes)
10 Aug 2013CPOL1 min read 71.1K   13   4
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):

HTML
<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):

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 3 Pin
satish koladiya26-Aug-13 23:34
professionalsatish koladiya26-Aug-13 23:34 
GeneralMy vote of 5 Pin
ketan italiya12-Aug-13 21:46
ketan italiya12-Aug-13 21:46 
GeneralMy vote of 1 Pin
Dmitry A. Efimenko12-Aug-13 8:03
Dmitry A. Efimenko12-Aug-13 8:03 
GeneralMy vote of 5 Pin
Carsten V2.010-Aug-13 22:15
Carsten V2.010-Aug-13 22:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.