Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Browser's refresh button is reposting data

Posted on 2004-09-13
2
Medium Priority
?
728 Views
Last Modified: 2012-06-22
I have a form on a webpage that a user fills and and then presses the submit button to store the data into a database.  The problem is that if the user presses the Refresh button on thier browser the data is posted a second time.

I have tried adding code that checks to see if the page was submitted already or not, but it is not working.  What am I doing wrong?  I can not redirect them to another page after submitting as this page sets certain panels to visible or not depending on whether or not there submission to the database was sucessful or not.

I set up a global variable called vSubmitted

In the Page_Load section I have the following:
If vSubmitted <> True Then
  vSubmitted = False
End If

Then down in my btnSubmit_Click subroutine I have:
If vSubmitted = False Then
  vSuccess = fnStoreData()
  vSubmitted = True
End If

But, a refresh is still submitting the data again.  Trace shows vSubmitted set to false when the page reloads.

I know that this type of question has been posted before, but I am not getting anywhere with what I have been able to find.

Thanks in advance,
Tom
0
Comment
Question by:TUmphress
2 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 12048810
A refresh is always going to repost the data, and it is up to you to figure out if they have already done that or not.  I would say your code to maintain this isn't working properly.  How is your vSubmitted variable persisted?  You can't use viewstate on this one...because you are submitting your old viewstate when you hit refresh, not the new one.
0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 500 total points
ID: 12048828
Use session to store the flag...
Change btnSubmit_Click subroutine:

If Not Session("vSubmitted") is Nothing Or Session("vSubmitted") = "False" Then
  vSuccess = fnStoreData()
  Session("vSubmitted") = "True"
End If

In Page_Load:

If Not Page.IsPostBack Then
   Session("vSubmitted")="False"
End If
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question