Solved

Browser's refresh button is reposting data

Posted on 2004-09-13
2
715 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 125 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now