To refresh your page you may use the javascript function:
window.location.reload();
For example you can use that on the OnClientClick attribute of an ASP.NET button:
<asp:button ID="btnRefresh" OnClick="btnRefresh_Click" runat="server" Text="REFRESH"
OnClientClick="window.location.reload();" />
The code above will work fine, but if let's say you have some other server-side logic you want to run on the code for btnRefresh_Click, it won't be executed because the page would already be refreshed by then.
So to run your server-side code, first remove the OnClientClick attribute on the asp button tag above. Then place the following code inside your button click event:
protected void btnRefresh_Click(object sender, EventArgs e)
{
//Your logic here...
Page.Response.Redirect(HttpContext.Current.Request.Url.ToString(), true);
}
We simply redirect the page to its current url and that does the trick.
-k
Subscribe to:
Post Comments (Atom)
Nice post.
ReplyDeleteSolved me one problem.
Thanks.
Thanks!
ReplyDeletesecond option worked for me
thanks! solves my Prob!
ReplyDeleteJust what I was looking for. Worked great, thanks.
ReplyDeleteThat wa great...Both worked for me!
ReplyDeletesüper bir kod. çok işime yaradı.
ReplyDeleteThanks a lot. It is the best for me
ReplyDeletesome page refresh but some page don't refresh.why?
ReplyDeleteThis was the perfect solution. I have been battling an issue with the .Net life cycle regarding:
ReplyDeletePre-Render
Page_Init
Page_Load
having these events occur before my button click event which was causing some data to not be refreshed in session states. This fixed my issue.
Thanks.
Good
ReplyDeleteon refresh i want to call code behind file on certain interval
ReplyDeleteI am extremely impressed along with your writing abilities, Thanks for this great share.
ReplyDeletethanx for helping its work
ReplyDeletegood Solution.. It's Working
ReplyDeleteBlogging is the new poetry. I find it wonderful and amazing in many ways.
ReplyDeleteHey keep posting such good and meaningful articles.
ReplyDeleteHey keep posting such good and meaningful articles.
ReplyDelete