简体   繁体   English

刷新页面C#ASP.NET

[英]Refresh Page C# ASP.NET

Is there a Page.Refresh type of command to refresh a page? 是否有Page.Refresh类型的命令来刷新页面?

I don't want to redirect to the page or refresh in JavaScript. 我不想重定向到页面或用JavaScript刷新。

我认为这应该成功(未经测试):

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

Careful with rewriting URLs, though. 但是要小心重写URL。 I'm using this, so it keeps URLs rewritten. 我正在使用它,因此它会保留URL重写。

Response.Redirect(Request.RawUrl);
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. 要从javascript执行此操作,您只需调用__doPostBack()函数即可。

Depending on what exactly you require, a Server.Transfer might be a resource-cheaper alternative to Response.Redirect . 根据您的具体要求, Server.Transfer可能是Response.Redirect的资源更便宜的替代品。 More information is in Server.Transfer Vs. 更多信息在Server.Transfer Vs. Response.Redirect . Response.Redirect

使用:

Response.Redirect(Request.RawUrl, true);

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

I use 我用

Response.Redirect(Page.Request.Path);

If you have to check for the Request.Params when the page is refresh use below. 如果您必须在页面刷新时检查Request.Params,请使用以下内容。 This will not rewrite the Request.Params to the URL. 这不会将Request.Params重写为URL。

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

调用Page_load函数:

Page_Load(sender, e);

刷新整个页面,但它正常工作:

Response.Redirect(url,bool) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM