Link to home
Start Free TrialLog in
Avatar of Iarfhlaith
Iarfhlaith

asked on

How to stop a page from refreshing

I'm using vbscript and ASP to write info to a database and to create a file. This all works fine, but if I refresh the page all sorts of horrible things happen. I get errors about not being able to insert duplicate primary keys etc....

So my question is how can I prevent users from refreshing my page?

I've tried to send a variable with the url using get, in the hopes that this would allow me to determine if the page had been linked from the correct page. If not then I would know not to run the code that if run more then once would create an error but it seems that if I refresh the page AFTER it has come from the correct page the get info is also refreshed which means that that idea won't work.

Any ideas anyone?

Iarfhlaith.
Avatar of sybe
sybe

well, i don't know your code, but i think keeping people from refreshing is a very cosmetic solution. Better rewrite your code.

Keeping people from refreshing is not really possible, it is something which is part of the browser. there are trick possible, but it's not stopping 100%.

I like to code:

Edit.asp (form, posted to Action.asp)
Action.asp (processes the data, and redirects to another page)

So after the form has been submitted the visitor comes at a completely different page that does nothing with the database. refreshing is no problem then
Avatar of Iarfhlaith

ASKER

thanks. I'll have another look at it. And cheers for the quick response.

Iarfhlaith
SOLUTION
Avatar of MannSoft
MannSoft

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks guys.

I've solved the problem by splitting up the code onto 2 pages. After the form is submitted, One page just for the script to insert to the database and then a quick re-direction to another that only holds the HTML for the user. That way, if they press the refresh button (and apparantly they will!) they only refresh the HTML and not the script. The use of the back button will also bring them back to the form and completely skip over the script only page.

The reason I was getting duplicate primary keys was I'm letting the user choose a name as one of the fields in the form. This name IS the primary key. Under normal use I do a simple check to see if that name exists in the database already and i protect against it that way. But this lttle select and compare is done on the form page as part of the form validation and isn't run when the user refreshes the next page.

So I've solved the problem by splitting the page into two: one for the script and one for the HTML.

Iarfhlaith.