Refresh(F5) page cause a sql insert again - trouble !!

U

User

Hi !
I have a sql insert function with a buttonin my page, and when i click on
refresh button of IE. When i click my button, i have a new records but after
when i click on the refresh button of IE (or F5) the sql insert again a
data records (my table have a automatic numeric key). How to prevent it ?

thanks for answering me fast !

PS : my trouble seems like this one :" I have a submit button that processes
a sql insert statement. How do I prevent the statment from resubmitting
itself when the user refreshes the page with either an F5 or with the IE
refresh option?"
 
K

Kevin Spencer

One solution is to do a Response.Redirect immediately after the DB
operation, thereby eliminating the same Form state when refreshing. For
example, you could do a Response.Redirect back to the same page.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 
B

bruce barker

this won't work if the user hits refresh before the response.

the best approach is to code for this behavior. put a transaction guid in a
hidden field on the form render. on the postback, check if the the
transaction has successfully completed before, or is still running.

if running wait for completion, and return results
if already done return previous results
first time - do it.

this will make your app bullet proof, plus allow resubmitting if the
internet loses the postback..

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top