Not allow resubmit of page

戏子无情 提交于 2019-12-06 11:32:56

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.

  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.

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.

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.

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.

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