I have a form submission via POST. I submit the form, and all is well, however if I try to reload the new page that the form goes to after submission, I get the "Do you want to resend data" message (Firefox). It might happen in other browsers too, but I'm not sure.
Is there a way to stop this message popping up so I can go ahead and refresh the page? It's not good for production environments - users may submit the same form twice!
You can prevent form resubmission via a session variable. Yes we can use microtime() as well as time() also instead of rand() , whatever function or variable that gives different value we can use it. BUT make sure that you set that value to SESSION variable.
Use the preventDefault() method on the event object to prevent a page refresh on form submit in React, e.g. event. preventDefault() . The preventDefault method prevents the browser from issuing the default action which in the case of a form submission is to refresh the page.
As you probably know, ASP.NET Web Forms send POST requests back to the server and then re-render the Page in the same request. This is why we see the form re-submission message when we click "reload". To avoid this issue, we should employ the post-then-redirect pattern used by many web applications.
You need to use the the POST-Redirect-GET pattern.
Make your form respond with a redirect to a GET request.
This way, when the user refreshes the page, it will only resend the GET.
An easy way after response.sendRedirect
is to reload the page in this way:
window.location.href = window.location.pathname;
It works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With