Click to See Complete Forum and Search --> : Prevent resubmission of form on refresh


lejo_kl
10-28-2003, 03:27 AM
I have an asp page that is used to submit a form to itself. The page is used to post comments from the user to itself. The values of the elements of the form are written onto the page on clicking the submit button.

I am faced with the problem of duplication of comments if someone presses the refresh button after submitting a form.

I am a novice in ASP. Can anyone please tell me if, there any way to avoid refresh of the form or to clear the form variable after one submission?

Please Help!!

rdoekes
10-28-2003, 05:47 AM
You could use a session variable to do this.
In your global.asa you add the following:

Sub Session_OnStart
Session("isPostBack") = false
End Sub
In your form
<%
If Request.Form.Count > 0 And _
Not Session("isPostBack") Then 'postback not occurred yet

Session("isPostBack") = True
'handle insert
End If
%>

If the user hits the refresh, the session variable is set to true, so it will skip the form handling.

That's one way of going about this.

Hope this helps,

-Rogier Doekes