Solved

Browser's refresh button is reposting data

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

760 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