|
 |
asp_databases thread: Clicking refresh button on browser will insert the same record again
Message #1 by "paul murphy" <paulmcn01@y...> on Tue, 25 Feb 2003 17:23:53
|
|
I am developing a database backed website using ASP as the front end, VB
for the middle tier business logic and SQL server 7 as the backend.
The problem I am having is as follows:
1.A user fills out some information in a text area at the bottom of a html
table on a web page.
2.They click a submit button which gets the information using the
request.form method, passes it to the appropriate VB component, which
inserts it into SQL server database.
3.The page is then loaded again with the new information the user entered
appended on to the bottom row of the table.
4The problem arises if the user now clicks the refresh button on their
browser. When they click the refresh button,the page loads again and the
request.form method must get the information again and put it into the
database again.
Basically I'm looking for some kind of way to do:
if(user has got to this page by clicking refresh) then
don't bother inserting the information into the db again.
Hope I explained clearly enough,
any help apprecaited
thanks
Message #2 by Mark Eckeard <meckeard2000@y...> on Tue, 25 Feb 2003 09:16:54 -0800 (PST)
|
|
There are many work arounds, but here are a few:
1 - Check the database to see if the value coming in
is the same as current value. If so, don't insert it.
2 - Before the page is submitted, set a session
variable (or value to a hidden text box) to false. If
the page gets submitted, check the value. If it's
false, the page was not submitted or refreshed.
Insert the data and set the variable to true. Now
every time the page loads, the true value will prevent
a duplicate entry.
3 - Redirect the user to a different page.
HTH,
Mark
--- paul murphy <paulmcn01@y...> wrote:
> I am developing a database backed website using ASP
> as the front end, VB
> for the middle tier business logic and SQL server 7
> as the backend.
> The problem I am having is as follows:
> 1.A user fills out some information in a text area
> at the bottom of a html
> table on a web page.
> 2.They click a submit button which gets the
> information using the
> request.form method, passes it to the appropriate VB
> component, which
> inserts it into SQL server database.
> 3.The page is then loaded again with the new
> information the user entered
> appended on to the bottom row of the table.
> 4The problem arises if the user now clicks the
> refresh button on their
> browser. When they click the refresh button,the page
> loads again and the
> request.form method must get the information again
> and put it into the
> database again.
>
> Basically I'm looking for some kind of way to do:
> if(user has got to this page by clicking refresh)
> then
> don't bother inserting the information into the db
> again.
>
> Hope I explained clearly enough,
> any help apprecaited
> thanks
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
Message #3 by "paul murphy" <paulmcn01@y...> on Tue, 25 Feb 2003 17:51:29
|
|
Thanks for the reply mark,I will have a few problems with these
suggestions though:
1)I am entering 3 values into the database.One of these is a long date
field.(ie)it has the date and the time.I can't reliably check this one
because it will always be different(the seconds at least will have
incremented).The other 2 fields are allowed have the same values as other
records entered before so I couldn't prevent an insertion if they are
identical.Even a combination of these two fields wouldn't provide me with
good odds of them being different!
2)If I set a session variable when the user enters information, then this
will prevent them entering any more information when the page is loaded
again. I want the user to be able to enter one piece of information, click
the submit, have it appended on to the table and then allow them the
opportunity to add another piece of information if they like.
3)This could be an option if all else fails but I'd like to remain on the
same page that they came from.
Once again thanks for the reply.I think I have ruled out these options by
though.IF you can see a flaw in my reasoning above please pick it out! or
any other options would be appreciated...thanks
>
There are many work arounds, but here are a few:
1 - Check the database to see if the value coming in
is the same as current value. If so, don't insert it.
2 - Before the page is submitted, set a session
variable (or value to a hidden text box) to false. If
the page gets submitted, check the value. If it's
false, the page was not submitted or refreshed.
Insert the data and set the variable to true. Now
every time the page loads, the true value will prevent
a duplicate entry.
3 - Redirect the user to a different page.
HTH,
Mark
--- paul murphy <paulmcn01@y...> wrote:
> I am developing a database backed website using ASP
> as the front end, VB
> for the middle tier business logic and SQL server 7
> as the backend.
> The problem I am having is as follows:
> 1.A user fills out some information in a text area
> at the bottom of a html
> table on a web page.
> 2.They click a submit button which gets the
> information using the
> request.form method, passes it to the appropriate VB
> component, which
> inserts it into SQL server database.
> 3.The page is then loaded again with the new
> information the user entered
> appended on to the bottom row of the table.
> 4The problem arises if the user now clicks the
> refresh button on their
> browser. When they click the refresh button,the page
> loads again and the
> request.form method must get the information again
> and put it into the
> database again.
>
> Basically I'm looking for some kind of way to do:
> if(user has got to this page by clicking refresh)
> then
> don't bother inserting the information into the db
> again.
>
> Hope I explained clearly enough,
> any help apprecaited
> thanks
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
Message #4 by Colin.Montgomery@C... on Tue, 25 Feb 2003 17:41:53 -0000
|
|
how about setting the value of the session variable equal to the Keyfield of
the record, once it's inserted? I.e. if you're using an Autonumber/Identity
field, simply insert the record, grab it's ID and write it to the session
variable. THis way, before you do each insert you can check if the record
exists already and alert the user as opposed to inserting a duplicate.
Would this work?
HTH,
Col
-----Original Message-----
From: paul murphy [mailto:paulmcn01@y...]
Sent: 25 February 2003 17:51
To: ASP Databases
Subject: [asp_databases] Re: Clicking refresh button on browser will
insert the same record again
Thanks for the reply mark,I will have a few problems with these
suggestions though:
1)I am entering 3 values into the database.One of these is a long date
field.(ie)it has the date and the time.I can't reliably check this one
because it will always be different(the seconds at least will have
incremented).The other 2 fields are allowed have the same values as other
records entered before so I couldn't prevent an insertion if they are
identical.Even a combination of these two fields wouldn't provide me with
good odds of them being different!
2)If I set a session variable when the user enters information, then this
will prevent them entering any more information when the page is loaded
again. I want the user to be able to enter one piece of information, click
the submit, have it appended on to the table and then allow them the
opportunity to add another piece of information if they like.
3)This could be an option if all else fails but I'd like to remain on the
same page that they came from.
Once again thanks for the reply.I think I have ruled out these options by
though.IF you can see a flaw in my reasoning above please pick it out! or
any other options would be appreciated...thanks
>
There are many work arounds, but here are a few:
1 - Check the database to see if the value coming in
is the same as current value. If so, don't insert it.
2 - Before the page is submitted, set a session
variable (or value to a hidden text box) to false. If
the page gets submitted, check the value. If it's
false, the page was not submitted or refreshed.
Insert the data and set the variable to true. Now
every time the page loads, the true value will prevent
a duplicate entry.
3 - Redirect the user to a different page.
HTH,
Mark
--- paul murphy <paulmcn01@y...> wrote:
> I am developing a database backed website using ASP
> as the front end, VB
> for the middle tier business logic and SQL server 7
> as the backend.
> The problem I am having is as follows:
> 1.A user fills out some information in a text area
> at the bottom of a html
> table on a web page.
> 2.They click a submit button which gets the
> information using the
> request.form method, passes it to the appropriate VB
> component, which
> inserts it into SQL server database.
> 3.The page is then loaded again with the new
> information the user entered
> appended on to the bottom row of the table.
> 4The problem arises if the user now clicks the
> refresh button on their
> browser. When they click the refresh button,the page
> loads again and the
> request.form method must get the information again
> and put it into the
> database again.
>
> Basically I'm looking for some kind of way to do:
> if(user has got to this page by clicking refresh)
> then
> don't bother inserting the information into the db
> again.
>
> Hope I explained clearly enough,
> any help apprecaited
> thanks
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
*******
This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not the
intended recipient, please telephone or email the sender and delete this message and any attachment from your system. If you are
not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.
For further information about Clifford Chance please see our website at http://www.cliffordchance.com or refer to any Clifford
Chance office.
Message #5 by "paul murphy" <paulmcn01@y...> on Wed, 26 Feb 2003 21:41:32
|
|
thanks for replying colin,
I'll run through anexample of your explanation just to make sure I got u
correct and then I'll show you how I'll still have problems!
1.I insert a record into the field and the autonumber of this field will
increment automatically when I insert the record(ie I don't have to pass
this value in my INSERT statement).
2. I then grab this autonumber field for the record I just entered from
the database and store it in the session variable.
3. The user is back to the page from where they entered the values just
previously. They then hit refresh on the browser. I go to check my session
variable and see if it corresponds to the number of the record that was
just entered. It was so the user can't enter record...
But the user might want to enter a new record, which they can do form this
page. The session variable will prevent them from doing this aswell right?
When they try to insert a new reocrd it will check then session variable
against the autonumber in the database and prevent the user from inserting.
So they will only be allowed to insert one record which I don't want!
> how about setting the value of the session variable equal to the
Keyfield of
the record, once it's inserted? I.e. if you're using an
Autonumber/Identity
field, simply insert the record, grab it's ID and write it to the session
variable. THis way, before you do each insert you can check if the record
exists already and alert the user as opposed to inserting a duplicate.
Would this work?
HTH,
Col
Message #6 by Colin.Montgomery@C... on Thu, 27 Feb 2003 12:15:52 -0000
|
|
you're absolutely right Paul - flawed logic on my part. I am interested to
find out how this could be accomplished, so i'll keep thinking about it and
post any ideas I have. If you do figure it out, it would be good if you
could post your solution.
Cheers,
Col
-----Original Message-----
From: paul murphy [mailto:paulmcn01@y...]
Sent: 26 February 2003 21:42
To: ASP Databases
Subject: [asp_databases] Re: Clicking refresh button on browser will i
nsert the same record again
thanks for replying colin,
I'll run through anexample of your explanation just to make sure I got u
correct and then I'll show you how I'll still have problems!
1.I insert a record into the field and the autonumber of this field will
increment automatically when I insert the record(ie I don't have to pass
this value in my INSERT statement).
2. I then grab this autonumber field for the record I just entered from
the database and store it in the session variable.
3. The user is back to the page from where they entered the values just
previously. They then hit refresh on the browser. I go to check my session
variable and see if it corresponds to the number of the record that was
just entered. It was so the user can't enter record...
But the user might want to enter a new record, which they can do form this
page. The session variable will prevent them from doing this aswell right?
When they try to insert a new reocrd it will check then session variable
against the autonumber in the database and prevent the user from inserting.
So they will only be allowed to insert one record which I don't want!
> how about setting the value of the session variable equal to the
Keyfield of
the record, once it's inserted? I.e. if you're using an
Autonumber/Identity
field, simply insert the record, grab it's ID and write it to the session
variable. THis way, before you do each insert you can check if the record
exists already and alert the user as opposed to inserting a duplicate.
Would this work?
HTH,
Col
*******
This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not the
intended recipient, please telephone or email the sender and delete this message and any attachment from your system. If you are
not the intended recipient you must not copy this message or attachment or disclose the contents to any other person.
For further information about Clifford Chance please see our website at http://www.cliffordchance.com or refer to any Clifford
Chance office.
Message #7 by "Gillian Harber" <gillian@m...> on Thu, 27 Feb 2003 14:17:06 -0000
|
|
I have a suggestion. It has sort of already been suggested, but not in the
way I'm going to suggest exactly.
Have your page with your form on it. This page gets submitted to an
entirely different page, this page collects the request.form data and does
whatever your page would orginally have done. At the end of the page that
is receiving the data you have a response.redirect back to the page with the
form on. Now the important bit, make sure the page you submit to (the one
collecting the data) has no html on it. The page you sumbitted the data to
will never reach the browser, hence clicking back only goes back to the page
with the form on (although you will be already on this page after the
redirect from the receiving data page). Clicking refresh will only refresh
the page since the page does not still have the form post data.
Hope that helps.
Gillian
----- Original Message -----
From: <Colin.Montgomery@C...>
To: "ASP Databases" <asp_databases@p...>
Sent: Thursday, February 27, 2003 12:15 PM
Subject: [asp_databases] Re: Clicking refresh button on browser will i nsert
the same reco rd again
> you're absolutely right Paul - flawed logic on my part. I am interested
to
> find out how this could be accomplished, so i'll keep thinking about it
and
> post any ideas I have. If you do figure it out, it would be good if you
> could post your solution.
>
> Cheers,
> Col
>
> -----Original Message-----
> From: paul murphy [mailto:paulmcn01@y...]
> Sent: 26 February 2003 21:42
> To: ASP Databases
> Subject: [asp_databases] Re: Clicking refresh button on browser will i
> nsert the same record again
>
>
> thanks for replying colin,
> I'll run through anexample of your explanation just to make sure I got u
> correct and then I'll show you how I'll still have problems!
> 1.I insert a record into the field and the autonumber of this field will
> increment automatically when I insert the record(ie I don't have to pass
> this value in my INSERT statement).
> 2. I then grab this autonumber field for the record I just entered from
> the database and store it in the session variable.
> 3. The user is back to the page from where they entered the values just
> previously. They then hit refresh on the browser. I go to check my session
> variable and see if it corresponds to the number of the record that was
> just entered. It was so the user can't enter record...
>
> But the user might want to enter a new record, which they can do form this
> page. The session variable will prevent them from doing this aswell right?
> When they try to insert a new reocrd it will check then session variable
> against the autonumber in the database and prevent the user from
inserting.
> So they will only be allowed to insert one record which I don't want!
>
> > how about setting the value of the session variable equal to the
> Keyfield of
> the record, once it's inserted? I.e. if you're using an
> Autonumber/Identity
> field, simply insert the record, grab it's ID and write it to the session
> variable. THis way, before you do each insert you can check if the record
> exists already and alert the user as opposed to inserting a duplicate.
>
> Would this work?
>
> HTH,
> Col
>
>
>
> *******
>
> This message and any attachment are confidential and may be privileged or
otherwise protected from disclosure. If you are not the intended recipient,
please telephone or email the sender and delete this message and any
attachment from your system. If you are not the intended recipient you must
not copy this message or attachment or disclose the contents to any other
person.
>
> For further information about Clifford Chance please see our website at
http://www.cliffordchance.com or refer to any Clifford Chance office.
>
>
>
Message #8 by "Ken Schaefer" <ken@a...> on Fri, 28 Feb 2003 16:48:56 +1100
|
|
How about we add just one little step to Colin's suggestion.
- Edit (2) so that it reads:
"We extract the Identity/Autonumber value and we store it in a
<input type="hidden" name="txtLastInsertedRecord>
form element on the page"
- Step (3) reads:
"When the user submits the form we grab the value of
Request.Form("txtLastInsertedRecord"). If this has no value, then this is
the first time the page has been loaded this session, so just insert the
data. If this has some value, then we do a lookup in the database. We do:
SELECT
1
FROM
myTable
WHERE
Field1 = 'SubmittedValue1'
AND
Field2 = 'SubmittedValue2'
AND
RecordID = SubmittedLastRecordID
Now, if there is a match across all these fields, then the "refresh" button
was pressed -or- the user resubmitted the form without updating any of the
fields.
If there is no match, then the user must have changed 1+ of the fields, so
we proceed with the insert.
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "paul murphy" <paulmcn01@y...>
To: "ASP Databases" <asp_databases@p...>
Sent: Wednesday, February 26, 2003 9:41 PM
Subject: [asp_databases] Re: Clicking refresh button on browser will i nsert
the same record again
: thanks for replying colin,
: I'll run through anexample of your explanation just to make sure I got u
: correct and then I'll show you how I'll still have problems!
: 1.I insert a record into the field and the autonumber of this field will
: increment automatically when I insert the record(ie I don't have to pass
: this value in my INSERT statement).
: 2. I then grab this autonumber field for the record I just entered from
: the database and store it in the session variable.
: 3. The user is back to the page from where they entered the values just
: previously. They then hit refresh on the browser. I go to check my session
: variable and see if it corresponds to the number of the record that was
: just entered. It was so the user can't enter record...
:
: But the user might want to enter a new record, which they can do form this
: page. The session variable will prevent them from doing this aswell right?
: When they try to insert a new reocrd it will check then session variable
: against the autonumber in the database and prevent the user from
inserting.
: So they will only be allowed to insert one record which I don't want!
:
: > how about setting the value of the session variable equal to the
: Keyfield of
: the record, once it's inserted? I.e. if you're using an
: Autonumber/Identity
: field, simply insert the record, grab it's ID and write it to the session
: variable. THis way, before you do each insert you can check if the record
: exists already and alert the user as opposed to inserting a duplicate.
:
: Would this work?
:
: HTH,
: Col
:
|
|
 |