Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

asp.net

People also ask

How do you refresh a page in a script?

In JavaScript, you refresh the page using document. location. reload() . You can add the true keyword to force the reloaded page to come from the server (instead of cache).

How do I trigger a refresh page?

reload() method reloads the current web page. The method gives the exact same result as pressing the RELOAD button in your browser. The JavaScript reload page method loads the page from the cache by default. If the forceGet property is set to true, the page is reloaded from the server.

How can I tell if ASP NET is refreshing a page?

'IsPostback' will always have the value which was set previously. So for instance if the page was posted back before refresh, then the value will be true and if the page is not posted back before refresh, then the value will be false.

How do you call a function when a page reloads?

You need to call myFunction() when the page is loaded. window. onload = myFunction; If you only want to run it when the page is reloaded, not when it's loaded for the first time, you could use sessionStorage to pass this information.


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.


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.


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.


Try this:

Response.Redirect(Request.Url.AbsoluteUri);

Use javascript's location.reload() method.

<script type="text/javascript">
  function reloadPage()
  {
    window.location.reload()
  }
</script>

There are various method to refresh the page in asp.net like...

Java Script

 function reloadPage()
 {
     window.location.reload()
 }

Code Behind

Response.Redirect(Request.RawUrl)

Meta Tag

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

Page Redirection

Response.Redirect("~/default.aspx"); // Or whatever your page url

If you don't want to do a full page refresh, then how about wrapping what you want to refresh inside of a UpdatePanel and then do an asynchronous postback?