How do I refresh a page in ASP.NET? (Let it reload itself by code)
I\'d rather not use Response.Redirect() because I don\'t know if the page I will be on, as it\'s i
You can use 2 ways for solve this problem: 1) After the head tag
<head>
<meta http-equiv="refresh" content="600">
</head>
2) If your page hasn't head tag you must use Javascript to implement
<script type="text/javascript">
function RefreshPage()
{
window.location.reload()
}
</script>
My contact:
http://gola.vn
The only correct way that I could do page refresh was through JavaScript, many of top .NET answers failed for me.
Response.Write("<script type='text/javascript'> setTimeout('location.reload(true); ', timeout);</script>");
Put the above code in button click event or anywhere you want to force page refresh.
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?
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.
Use javascript's location.reload() method.
<script type="text/javascript">
function reloadPage()
{
window.location.reload()
}
</script>
for asp.net core 3.1
Response.Headers.Add("Refresh", "2");// in secound
and
Response.Headers.Remove("Refresh");