Refresh Page C# ASP.NET

Viewed 251609

Is there a Page.Refresh type of command to refresh a page?

I don't want to redirect to the page or refresh in JavaScript.

10 Answers

I think this should do the trick (untested):

Page.Response.Redirect(Page.Request.Url.ToString(), true);
Response.Redirect(Request.Url.ToString());

You can just do a regular postback to refresh the page if you don't want to redirect. Posting back from any control will run the page lifecycle and refresh the page.

To do it from javascript, you can just call the __doPostBack() function.

You shouldn't use:

Page.Response.Redirect(Page.Request.Url.ToString(), true);

because this might cause a runtime error.

A better approach is:

Page.Response.Redirect(Page.Request.Url.ToString(), false);
        Context.ApplicationInstance.CompleteRequest();
Related