Home All Groups Group Topic Archive Search About
Author
19 Jan 2006 6:44 PM
Mr Newbie
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  º¿º

Author
19 Jan 2006 7:14 PM
cbrown
Add this to your page_load event

If Not Page.IsPostBack Then
  'The code currently in your Load event
End If
Author
19 Jan 2006 7:40 PM
Mr Newbie
No that wont help because this form can postback several times, it is the
false submission which I am after, in other words  the code behind the
submit button re-runs on refresh

--
Best Regards

The Inimitable Mr Newbie  º¿º
<cbr***@duclaw.com> wrote in message
Show quoteHide quote
news:1137698093.021034.80690@z14g2000cwz.googlegroups.com...
> Add this to your page_load event
>
> If Not Page.IsPostBack Then
>  'The code currently in your Load event
> End If
>
Author
19 Jan 2006 8:26 PM
cbrown
Well, I guess it really depends on what the code does.  You could store
something in View or Session state that gets checked on each submit.
Depends how you feel about Session objects.  Cant help much more
without seeing the code or knowing what the code does.
Author
19 Jan 2006 10:22 PM
_AnonCoward
Show quote Hide quote
"Mr Newbie" <h***@now.com> wrote in message
news:%23ZSECiSHGHA.344@TK2MSFTNGP11.phx.gbl...
: 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
--
--
----------------------------------------------------------
*             ^~^                   ^~^                  *
*          _ {~ ~}                 {~ ~} _               *
*         /_``>*<                   >*<''_\              *
*        (\--_)++)                 (++(_--/)             *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
Author
19 Jan 2006 10:34 PM
Mr Newbie
Excellent reply Ralf. I think I need to think this throught after what you
have suggested.

Thanks

--
Best Regards

The Inimitable Mr Newbie  º¿º
Show quoteHide quote
"_AnonCoward" <abc***@uvwxyz.com> wrote in message
news:SiUzf.24662$Kp.23139@southeast.rr.com...
>
> "Mr Newbie" <h***@now.com> wrote in message
> news:%23ZSECiSHGHA.344@TK2MSFTNGP11.phx.gbl...
> : 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
> --
> --
> ----------------------------------------------------------
> *             ^~^                   ^~^                  *
> *          _ {~ ~}                 {~ ~} _               *
> *         /_``>*<                   >*<''_\              *
> *        (\--_)++)                 (++(_--/)             *
> ----------------------------------------------------------
> There are no advanced students in Aikido - there are only
> competent beginners. There are no advanced techniques -
> only the correct application of basic principles.
>
>
>
Author
19 Jan 2006 10:46 PM
Mr Newbie
here's an article dedicated for the subject

Preventing Duplicate Record Insertion on Page Refresh
http://aspalliance.com/687


--
Best Regards

The Inimitable Mr Newbie  º¿º
Show quoteHide quote
"_AnonCoward" <abc***@uvwxyz.com> wrote in message
news:SiUzf.24662$Kp.23139@southeast.rr.com...
>
> "Mr Newbie" <h***@now.com> wrote in message
> news:%23ZSECiSHGHA.344@TK2MSFTNGP11.phx.gbl...
> : 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
> --
> --
> ----------------------------------------------------------
> *             ^~^                   ^~^                  *
> *          _ {~ ~}                 {~ ~} _               *
> *         /_``>*<                   >*<''_\              *
> *        (\--_)++)                 (++(_--/)             *
> ----------------------------------------------------------
> There are no advanced students in Aikido - there are only
> competent beginners. There are no advanced techniques -
> only the correct application of basic principles.
>
>
>
Author
20 Jan 2006 6:57 AM
Cor Ligthert [MVP]
Mr. Newbie,

From the previous messages I get the idea that you are using an autokey. Try
to avoid that. The nicest recordidentifier in a database is the GUID

http://www.vb-tips.com/default.aspx?ID=b57d0ce2-3f5f-47d4-9663-fee3733fcd6f

I hope this helps,

Cor
Author
21 Jan 2006 1:45 AM
Dennis
Question;  Why is the submit button click event fired if a page is refreshed?
--
Dennis in Houston


Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> Mr. Newbie,
>
> From the previous messages I get the idea that you are using an autokey. Try
> to avoid that. The nicest recordidentifier in a database is the GUID
>
> http://www.vb-tips.com/default.aspx?ID=b57d0ce2-3f5f-47d4-9663-fee3733fcd6f
>
> I hope this helps,
>
> Cor
>
>
>
Author
21 Jan 2006 1:53 PM
Mr Newbie
Because the client must repost the header which has is a POST. I think
explorer seems to go one step further and emulates the last post completely
even if you clear the headers on pre-render event.

--
Best Regards

The Inimitable Mr Newbie  º¿º
Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:60CBE176-9E6E-4E70-AA13-85A51A95D437@microsoft.com...
> Question;  Why is the submit button click event fired if a page is
> refreshed?
> --
> Dennis in Houston
>
>
> "Cor Ligthert [MVP]" wrote:
>
>> Mr. Newbie,
>>
>> From the previous messages I get the idea that you are using an autokey.
>> Try
>> to avoid that. The nicest recordidentifier in a database is the GUID
>>
>> http://www.vb-tips.com/default.aspx?ID=b57d0ce2-3f5f-47d4-9663-fee3733fcd6f
>>
>> I hope this helps,
>>
>> Cor
>>
>>
>>