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");