Home | Software | WebLog | Contact | Wish List

Refresh Detection (Asp.NET)

Overview

Many websites suffer from the form browser refresh problem. For example, let's say you have a shopping cart. After the user buys item X, the page displays an invoice. The user refreshes the page, which asks if he'd like to repost the form. The user clicks "Retry" and the form is submitted again, charging his credit card and adding a duplicate order.

To fix this problem I have created a control (inspired by Dino Esposito's browser refresh detection code) that can be simply slipped into every page that may suffer from the form repost problem.

If you found this or any other code on this site usefull and want to show your appreciation, now you can. Thanks!

Example

Below is an example; a button that posts a form. (Most forms have text box fields, but for this example they are not necessary and have been omitted).

Page Status: This page has NOT been refreshed.
Button Status: This button has been clicked 0 times.



Click the button and press your browsers refresh button to test the refresh detection.


My contact form now detects browser refresh to eliminate multiple submissions. Please feel free to test it out and send me an email :)

Visual Studio Toolbox Installation

Add the control to your toolbox. Go to Tools > Customize Toolbox. Click the tab .Net Framework Components. Click on Browse, locate Joel.Net.Refresh.dll and click ok. You should now see "Refresh" in the toolbox.

post reply to this comment Comment by Luis Lazcano [Jan 07, 2008 @ 11:24 PM]
Hey, i have been working to solve shopping cart issues in a new .NET development and yours is the only simple solution, maybe i made mistakes when trying to implement other solutions (like Dino Esposito among them) but i worked hard and couldn't make them work Until i stumbled with this page. Thank you so much.
post reply to this comment Comment by Ed Hinton [Jan 23, 2008 @ 6:29 PM]
Unfortunately, thius control seems to suffer from the same problem all the other solutions I've found does.  It doesn't work if the URL is being displayed within an iframe of another page.  For some reason, the first time the button is clicked, it increments the counter.  After that, clicking the button acts as if it is the browser refresh.    Any ideas on how to get it to work even if the page is displayed within an iframe?  In my app, I have to embed it in an iframe of an app I do not have source code for, so I need a solution that works by itself even when embedded in an iframe.

Thanks for any ideas on this.

post reply to this comment Comment by gdfg [Jan 06, 2009 @ 9:10 PM]
dggd
post reply to this comment Comment by David [Mar 30, 2009 @ 7:54 PM]
very nice!
post reply to this comment Comment by Abdikarim [May 01, 2009 @ 10:28 PM]
Thanks it seems to be fucntioning proberly
post reply to this comment Comment by MAM. Azeem [Dec 20, 2009 @ 11:37 PM]
Thank you so much dear!!!!!! it solved my big headache........... thanks in advance!!!!! Azm The BeTa
Leave Your Comment
Name:
Email:  (gravatar enabled)
URL:
Comment:
or Cancel