Click here to Skip to main content
Click here to Skip to main content
Go to top

Automatic Page Refresh in ASP.NET

, 10 Aug 2013
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Srinivas Kalabarigi
Software Developer (Senior)
India India

Around 8 years of software development experience and involved in analysis, design, development, testing and deployment of enterprise web applications for government, healthcare and banking domain with good exposure to object-oriented design, software architectures, design patterns, test-driven development and agile practices.

 
Educational Background
  • Post Graduation in Computer Science from Andhra University, India.
  • Graduation in Mathematics, Electronics and Computer Science from Andhra University, India.
  • Diploma in Software Technology from CMC Ltd., India.

Comments and Discussions

 
GeneralMy vote of 3 Pinprofessionalsatish koladiya26-Aug-13 23:34 
GeneralMy vote of 5 Pinprofessionalketan italiya12-Aug-13 21:46 
GeneralMy vote of 1 PinmemberDmitry A. Efimenko12-Aug-13 8:03 
GeneralMy vote of 5 PinmemberCarsten V2.010-Aug-13 22:15 

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

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

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 10 Aug 2013
Article Copyright 2013 by Srinivas Kalabarigi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid