Eric
Eric

Reputation: 8088

Refresh Page C# ASP.NET

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.

Upvotes: 57

Views: 288126

Answers (11)

vblover
vblover

Reputation: 1

I use # for Current page url address at Redirect to Refresh and that working currectly. What do you think about this:

Response.Redirect("#")

Upvotes: 0

Beniamin Makal
Beniamin Makal

Reputation: 162

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();

Upvotes: 4

Dan Ng
Dan Ng

Reputation: 11

I use

Response.Redirect(Page.Request.Path);

If you have to check for the Request.Params when the page is refresh use below. This will not rewrite the Request.Params to the URL.

Response.Redirect(Page.Request.Path + "?Remove=1");

Upvotes: 0

Paulo
Paulo

Reputation: 1

Call Page_load function:

Page_Load(sender, e);

Upvotes: -3

Jack Marchetti
Jack Marchetti

Reputation: 15754

Response.Redirect(Request.Url.ToString());

Upvotes: 7

Tomas Vana
Tomas Vana

Reputation: 18785

Depending on what exactly you require, a Server.Transfer might be a resource-cheaper alternative to Response.Redirect. More information is in Server.Transfer Vs. Response.Redirect.

Upvotes: 2

Webdesign
Webdesign

Reputation: 17

To refresh the whole page, but it works normally:

Response.Redirect(url,bool) 

Upvotes: -5

Syed Umar Ahmed
Syed Umar Ahmed

Reputation: 5962

Use:

Response.Redirect(Request.RawUrl, true);

Upvotes: 3

Bondt
Bondt

Reputation: 798

Careful with rewriting URLs, though. I'm using this, so it keeps URLs rewritten.

Response.Redirect(Request.RawUrl);

Upvotes: 20

womp
womp

Reputation: 116987

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.

Upvotes: 6

Fermin
Fermin

Reputation: 36111

I think this should do the trick (untested):

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

Upvotes: 130

Related Questions