Prevent Form Resubmission in ASP.Net (without redirecting to myself)
The issue is you're doing a form POST which, if the user subsequently refreshes the page, does what it's supposed to do: resubmit the POST. There is no way around it. Therefore, the options available to you are as follows:
- Redirect to a confirmation page, passing the operation results to the confirmation page in some way (typically reload from some data repository if it's something that's not feasible for a query string/cookie/etc.).
- Redirect to the same page, but pass the success message via a query string parameter (or go silly and store it in the session/ViewState/what-have-you-silliness).
- Instead of posting, do a form get since it seems you aren't posting any values, only initiating some sort of server-side processing. To do so simply change your form from a post to a get, or just do a link. The danger here is you shouldn't be doing any transformative/destructive operations in any get operation.
NOTE: make sure you sanitize any and all user input (treat user input as evil always).
You probably would be happiest with the last option, but it all depends on what "do a bunch of stuff and put the results in syncResults..." really entails.
UPDATE (years later)
While it should be obvious it might not be obvious enough to some users: you should NEVER open yourself up to XSS attacks by directly displaying un-sanitized "success message via a query string parameter". The suggestions assumed this was obvious, but in retrospect it should have been explicitly clear in that regard.