How do I refresh the page in ASP.NET? (Let it reload itself by code)

Try this:

Response.Redirect(Request.Url.AbsoluteUri);

In my user controls, after updating data I do:

  Response.Redirect(Request.RawUrl);    

That ensures that the page is reloaded, and it works fine from a user control. You use RawURL and not Request.Url.AbsoluteUri to preserve any GET parameters that may be included in the request.

You probably don't want to use: __doPostBack, since many aspx pages behave differently when doing a postback.


Once the page is rendered to the client you have only two ways of forcing a refresh. One is Javascript

setTimeout("location.reload(true);", timeout);

The second is a Meta tag:

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

You can set the refresh intervals on the server side.


This might be late, but I hope it helps someone who is looking for the answer.

You can use the following line to do that:

Server.TransferRequest(Request.Url.AbsolutePath, false);

Try to avoid using Response.Redirect as it increases the steps in the process. What it actually does is:

  1. Sends back the page with redirection header
  2. The Browser redirects to the destination URL.

As you can see, the same outcome takes 2 trips rather than 1 trip.

Tags:

Asp.Net