Preventing webform resubmission on browser refresh without losing viewstate

血红的双手。 提交于 2019-12-19 03:44:07

问题


Duplicate: How can I prevent database being written to again when the browser does a reload/back?


Is there a nice elegant way to stop an .aspx page from resubmitting form data if the user requests a refresh from their browser?

Ideally without losing the viewstate.

EDIT: The most elegant solution for me turned out to be wrapping the relevant controls in an asp.net ajax UpdatePanel. Ta everyone.


回答1:


There is no elegant way, but there are options. As stated in one of the other answers you can do a HTTP redirect response. Another solution is submitting through means such as Ajax, or through an iframe.




回答2:


Generate and insert a unique identifier into the page that's also stored on the server. Store that when the form is submitted and don't let that value get passed in multiple times.

UPDATE: This is the only "proper" way to do this. When I say this, I mean storing something on the server side. Anything based on client behaviour is potentially buggy. Those implementations don't concern themselves with potential browser bugs, incompatibilities, javascript disabled, connection timeouts etc.

Something on the server side needs to know that this particular action has already been performed and stop it on the server side. I stress this, because often this needs to be done to stop a client refreshing and making multiple orders (and potentially multiple bills). This also allows the client to refresh gracefully if the action hasn't actually been received and acted upon by the server (e.g. in the case of a timeout).




回答3:


redirect after post



来源:https://stackoverflow.com/questions/542284/preventing-webform-resubmission-on-browser-refresh-without-losing-viewstate

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