F5 Refresh on Forms

balaacoully

New Member
I have a .aspx which contains a form which posts back to itself. Is there anyway to prevent the message which appears if the client side presses the F5 Refresh button after posting. The situation I have is that values are being posted into the database twice. Once when they click submit the first time, and once again when they press F5 to refresh the page.<BR><BR>CheersNot sure if this can help but checkout the IsPostBack property<BR><BR>it is a read-only Boolean property that indicates if the page or control is being loaded for the first time, or if it is being loaded in response to a client postback.The fix is simpler than you might think. I hope this solution doesn't come too late. Set a session variable to true if not IsPostBack. After you update your database, set the variable to false. Only do the update if the variable is true.<BR><BR>If Not IsPostBack Then<BR> Session("UpdateAllowed") = True<BR>End If<BR><BR>...<BR><BR>If Session("UpdateAllowed") Then<BR> 'Update database...<BR>End If<BR><BR>Hope that helps...I didn't include the line where the Session variable is modified:<BR><BR>If Not IsPostBack Then <BR> Session("UpdateAllowed") = True <BR>End If <BR><BR>... <BR><BR>If Session("UpdateAllowed") Then <BR> 'Update database... <BR> Session("UpdateAllowed") = False<BR>End If <BR><BR>&nbsp;<BR>Just clear the form after you submitted the data succesfully to the server. Then there's no way data can ben send twice.<BR><BR>Henri<BR>That's not true. Clearing the form after submitting guards against a user submitting the form, then submitting it again. If a user submits the data once, however, then the form is cleared, hitting the refresh button on the browser will allow the user to repost whatever data was just sent, regardless of what's on the current page. You know when you refresh a page (after submitting a form - or doing a postback in .NET), you get a warning that the page expired, and you get the option to Retry or Cancel. If you click Retry, all the data that was sent to the page originally (from the first successful submission) will be re-sent. If you allow duplicates in your database, a duplicate entry will be made, otherwise, an error will be thrown.
 
Back
Top