How do I use the “Post/Redirect/Get” a.k.a. “Redirect after Post” with asp.net

寵の児 提交于 2020-01-10 15:44:26

问题


Doing a refresh after certain action in asp.net seems to make them happen again even when that action doesn't make sense (think double delete). The web way to deal with this situation is to redirect after a post to get a clean version of the page that can be refreshed without reposting an action to the webserver. How can I do this with ASP.NET


回答1:


I have a feeling there is a deeper problem I'm not getting but here goes. In your postback event:

// the post handling logic, e.g. the click event code
Response.Redirect(Request.RawUrl);



回答2:


Use Server.Transfer method.

The Server.Transfer method has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

http://www.developer.com/net/asp/article.php/3299641



来源:https://stackoverflow.com/questions/331277/how-do-i-use-the-post-redirect-get-a-k-a-redirect-after-post-with-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!