不允许重新提交页面

发布于 2024-10-31 03:04:31 字数 178 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

记忆消瘦 2024-11-07 03:04:32

提交后,您可以将表单已提交的事实保存在会话变量中。提交表单后,您首先测试此变量。如果变量为 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.

楠木可依 2024-11-07 03:04:31

您可以按照 Wikipedia 上的详细说明实施 Post Redirect Get 模式来删除刷新和双回发。

You can implement the Post Redirect Get pattern as detailed here on Wikipedia to remove the refresh and double postback.

苏辞 2024-11-07 03:04:31

如果绝对重要的是提交内容永远不会被处理两次,请将以上所有内容结合起来。

  1. 在提交按钮上放置一些 onclick javascript 以禁用或隐藏它,按照 Andre 的评论
  2. 按照 Daz Lewis 的链接实现 Post/Redirect/Get,以确保在浏览器上点击刷新不会重新提交表单
  3. 最后,添加一个隐藏字段,会话变量等,根据马特·格里尔和艾莉森的建议,所以如果某些事情确实通过了 - 例如,在发布和重定向之间连接超时,并且用户在浏览器上点击刷新 - 你不会在后面双重处理它结尾。

If it's absolutely vital that submissions never get processed twice, combine all of the above.

  1. Put some onclick javascript on the submit button to disable or hide it, as per Andre's comment
  2. Implement Post/Redirect/Get as per Daz Lewis's link to ensure that hitting refresh on the browser won't resubmit the form
  3. Finally, add a hidden field, session variable, etc., as per Matt Greer and Alison's suggestion, so if something does get through - e.g. connection times out in between the post and redirect, and user hits refresh on browser - you don't double-process it at your back end.
舞袖。长 2024-11-07 03:04:31

我认为对于“后退”按钮,您没有任何选择,只能再次检查表单提交上的值,并确定它是否是重新提交的表单。
您还有另一种选择,即提交后重定向到名为 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.

别闹i 2024-11-07 03:04:31

您可以使用 AJAX 从文本框中发布数据,这更好,因为您不会有“后退”按钮。

对于小东西(一个字段,小信息),我使用这个:

$.post("savedata.aspx", { name: "John", time: "2pm" } );

看看其他示例,它可能有用。

只需记住在您的项目中引用 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:

$.post("savedata.aspx", { name: "John", time: "2pm" } );

Take a look at the others examples, it might be useful.

Just remember to reference jQuery in your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文