Refresh Page C# ASP.NET

2019-01-18 01:41发布

问题:

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.

回答1:

I think this should do the trick (untested):

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


回答2:

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

Response.Redirect(Request.RawUrl);


回答3:

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


回答4:

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.



回答5:

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.



回答6:

Use:

Response.Redirect(Request.RawUrl, true);


回答7:

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


回答8:

Call Page_load function:

Page_Load(sender, e);



回答9:

To refresh the whole page, but it works normally:

Response.Redirect(url,bool)