刷新页面 C# ASP.NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2240287/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Refresh Page C# ASP.NET
提问by Eric
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 中重定向到页面或刷新。
采纳答案by Fermin
I think this should do the trick (untested):
我认为这应该可以解决问题(未经测试):
Page.Response.Redirect(Page.Request.Url.ToString(), true);
回答by Hyman Marchetti
Response.Redirect(Request.Url.ToString());
回答by womp
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() 函数即可。
回答by Tomas Vana
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.
根据您的确切需求, aServer.Transfer
可能是Response.Redirect
. 更多信息在Server.Transfer Vs 中。响应.重定向。
回答by Webdesign
To refresh the whole page, but it works normally:
刷新整个页面,但工作正常:
Response.Redirect(url,bool)
回答by Syed Umar Ahmed
Use:
用:
Response.Redirect(Request.RawUrl, true);
回答by Bondt
Careful with rewriting URLs, though. I'm using this, so it keeps URLs rewritten.
不过,重写 URL 时要小心。我正在使用它,因此它会重写 URL。
Response.Redirect(Request.RawUrl);
回答by Paulo
Call Page_load function:
调用 Page_load 函数:
Page_Load(sender, e);
Page_Load(sender, e);
回答by Dan Ng
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.
如果您必须在页面刷新时检查 Request.Params,请在下面使用。这不会将 Request.Params 重写为 URL。
Response.Redirect(Page.Request.Path + "?Remove=1");
回答by Beniamin Makal
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();