How to handle page refresh (F5)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have written a web form, which has a 'Add' button which saves all the input data from the form to a DB table
Now once that is done, if the user refreshes the browser page, it again insets the same data to the database! (as obvious as it is reposting whole data to the server)

How can I stop it?

Thanks in advance
 
Surajit said:
I have written a web form, which has a 'Add' button which saves all
the input data from the form to a DB table.
Now once that is done, if the user refreshes the browser page, it
again insets the same data to the database! (as obvious as it is
reposting whole data to the server).

How can I stop it??

Thanks in advance.

Normally, the user gets a warning about this (in IE: "The page cannot
be refreshed without resending the information", Retry/Cancel).
Therefore, the user is supposed to be aware of the dangers (especially
when confirming an online purchase!).

You can check the session ID (Session.SessionID), which is unique for
each user session. I guess you also have to check the posted data,
as you probably want to allow several inserts by the same user as long
as the data is different.
 
Surajit said:
I have written a web form, which has a 'Add' button which saves all
the input data from the form to a DB table.
Now once that is done, if the user refreshes the browser page, it
again insets the same data to the database! (as obvious as it is
reposting whole data to the server).

How can I stop it??

You can apply the synchronizer token pattern here. If you speak a little
Java, http://www.javaworld.com/javatips/jw-javatip136_p.html should get you
started.

Cheers,
 
Back
Top