不允许重新提交页面
我有一个 ASP.NET 4.0 Web 表单。我希望用户提交并检查一个文本框。如果是 正确,我清空了文本框,并且不希望用户能够重新提交该数据。在 IE8 中,用户可以回击(收到重新提交警告),如果刷新,它将重新提交该文本框中的数据。
我尝试将值设置为 null 并禁用文本框的视图状态。
如何停止重新提交?
I have an ASP.NET 4.0 web form. There is a textbox I want users to submit and check. If it's
correct, I blank out the textbox and don't want users to be able to resubmit that data. In IE8, users can hit back (get a resubmit warning) and if they refresh, it will resubmit the data from that text box.
I've tried setting the value to null and disabling viewstate for the textbox.
How do I stop resubmit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
提交后,您可以将表单已提交的事实保存在会话变量中。提交表单后,您首先测试此变量。如果变量为 true(或者无论您将其设置为什么),则不执行任何操作。用户可以刷新并且不会重新提交任何内容。
Upon submit, you can save the fact that the form has been submitted in a session variable. When the form is submitted, you first test for this variable. If the variable is true (or whatever you set it to be) then do nothing. The user can refresh and nothing will be resubmitted.
您可以按照 Wikipedia 上的详细说明实施 Post Redirect Get 模式来删除刷新和双回发。
You can implement the Post Redirect Get pattern as detailed here on Wikipedia to remove the refresh and double postback.
如果绝对重要的是提交内容永远不会被处理两次,请将以上所有内容结合起来。
If it's absolutely vital that submissions never get processed twice, combine all of the above.
我认为对于“后退”按钮,您没有任何选择,只能再次检查表单提交上的值,并确定它是否是重新提交的表单。
您还有另一种选择,即提交后重定向到名为 test.aspx 的中间页面,该中间页面会重定向到您的目标页面,因此在这种情况下后退按钮将不起作用。
I don't think that regarding to the Back button you have any choice but to check the value on form submit again, and determine that if it is the resubmitted form or not.
You have one other choice which is after submission redirect to a middle page named test.aspx which redirects to your destination page, so in this situation back button won't work.
您可以使用 AJAX 从文本框中发布数据,这更好,因为您不会有“后退”按钮。
对于小东西(一个字段,小信息),我使用这个:
看看其他示例,它可能有用。
只需记住在您的项目中引用 jQuery 即可。
You can post the data from the textbox using AJAX, which is better since you will not have "Back" button.
For small stuff (one field, small info) I use this one:
Take a look at the others examples, it might be useful.
Just remember to reference jQuery in your project.