: Before someone flames me, I know this is the VB.NET groups, nonetheless,
: the asp.net guys seems to have almost disapeared from the aspnet groups
: so I thought I would ask this here.
:
: I have a problem with an aspx web form in that if I refresh, it simply
: resubmits the form and causes multiple submissions, in this case the form
: is one which adds records to the database and refreshing a previously
: submitted item repeats each time the refresh is clicked.
:
: Does anyone have a suggestion on how I can get around this ?
:
: Thanks
:
: --
: Best Regards
:
: The Inimitable Mr Newbie º¿º
I had a problem like that once. What I ended up doing was creating a field
in my database that stored a submission ID and checking it when the page is
submitted. When the page was initially loaded (not the post back), a unique
value (including date time stamp in this case) was generated and included as
a hidden field in the form.
When the form was submitted I'd check that value to see if it existed in the
database. If it didn't, I allowed the submission to be inserted into the
database and I returned a response method appropriate the specifics of this
submission. Part of the insert action was to add this value into the record.
If the page was resubmitted, the same value would exist in the database when
the page was processed. In this case, I did not attempt to update the
database a 2nd time with the same values. I didn't object to the user or
anything but instead simply returned the same response that I would have if
I accepted the values.
There is at least one down side to this. If the user actually refreshes the
page, a new ID value would be generated and if submitted, the values would
be inserted twice because the system would think of this as a unique
submission. To get around that, I actually created the ID value two pages
back and passed it forward in hidden fields. Each page would POST to the
next in a cascading fashion. If the page in question was accessed directly
(or for any other reason the ID field wasn't present in the Request.Form
object when the page initially loaded), I'd redirect the user to the home
page and force them to start over. That way they couldn't jump into the
middle of the process and bypass this check.
This way, the user would have to back up two pages and refresh in order to
generate a new ID value. What actually happens is that the users start over
with a new process which was the intention all along (the refresh/resubmits
were never deliberate, rather they were the result of users being impatient
and not understanding what was happening).
I was never fully happy with the process (it just seemed somehow awfully
contrived to me), but it works. We eliminated duplicate submissions in our
system and the users seem no worse for the wear. This doesn't seem to be
exactly what you are talking about, but perhaps a variation of this approach
may serve your purposes.
Ralf