Refresh Page C# ASP.NET

C#.Netasp.netVisual StudioRefresh

C# Problem Overview


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.

C# Solutions


Solution 1 - C#

I think this should do the trick (untested):

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

Solution 2 - C#

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

Response.Redirect(Request.RawUrl);

Solution 3 - C#

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

Solution 4 - C#

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.

Solution 5 - C#

Use:

Response.Redirect(Request.RawUrl, true);

Solution 6 - C#

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

Solution 7 - C#

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.

Solution 8 - C#

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

Solution 9 - C#

Call Page_load function:

Page_Load(sender, e);

Solution 10 - C#

To refresh the whole page, but it works normally:

Response.Redirect(url,bool) 

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEricView Question on Stackoverflow
Solution 1 - C#FerminView Answer on Stackoverflow
Solution 2 - C#BondtView Answer on Stackoverflow
Solution 3 - C#Jack MarchettiView Answer on Stackoverflow
Solution 4 - C#wompView Answer on Stackoverflow
Solution 5 - C#Syed Umar AhmedView Answer on Stackoverflow
Solution 6 - C#Beniamin MakalView Answer on Stackoverflow
Solution 7 - C#Tomas VanaView Answer on Stackoverflow
Solution 8 - C#Dan NgView Answer on Stackoverflow
Solution 9 - C#PauloView Answer on Stackoverflow
Solution 10 - C#WebdesignView Answer on Stackoverflow