Solved

Browser's refresh button is reposting data

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

948 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

18 Experts available now in Live!

Get 1:1 Help Now