Home
|
Software
|
WebLog
|
Contact
|
Wish List
navigation
software
RxFind - Search/Replace
.net DatabaseUtility lib.
GAlert - Gmail Notify
code, scripts, etc...
Akismet .Net 2.0 API
Price vs Cost
WebLogs / Blog
Page Comments
Cookie Detection
Refresh Detection
Global Error Handler
Easy HTTP .Net
California Lottery
ASP.NET HTML Template
Bookmarklets
tech articles
Extend ASP 2.0 security
Safe Web Surfing
toys and gadgets
T-Mobile Sidekick II
Sony DirecTiVo
GT I-Drive 6.0 (bike)
Bit Char-G (R/C car)
SolarSpeeder
Canon PowerShot s200
active projects
WebLogs
PageComments
WasArrested.com
mygurus.net
Refresh Detection (Asp.NET)
Download binary project - 9 Kb
Download source project - 11 Kb
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
Darin
[Jul 15, 2004 @ 9:50 PM]
Know where I could get my hands on that refresh dection source code? Thanks, Darin
post reply to this comment
Comment by
Joel Thoms
[Jul 17, 2004 @ 1:28 AM]
I got it out of an old magazine. I don't think I have it anymore. you might be able to get the code sample here... http://www.dotmugs.ch/events/event.aspx?eid=17
post reply to this comment
Comment by
yarko
[Dec 10, 2004 @ 7:52 PM]
Yes, that code looks to be posted on that site, but you have to register w/ the Swiss user's group - and registration is only available for local people...
read replies to this comment
read replies to this comment
read replies to this comment
post reply to this comment
Comment by
Alexander Popov
[Apr 05, 2005 @ 4:26 AM]
It's not full protection. 1. open page 2. duplicate it ( ctrl-n ) 3. press Button on first ( OK ) 4. press Button on second. "This page HAS been refreshed." message appears ( Bug ) Did you know any techique to prevent this behavior?
post reply to this comment
Comment by
Joel Thoms
[Apr 12, 2005 @ 7:17 PM]
The code does not take into account simultaneous multiple requests from the same user. It may be possible to detect this by assigning a unique identifier when the page is first loaded. I'm currently working on other projects, but the source code is available and if anyone wishes to add this into the control, please send me the code and I will update the builds.
read replies to this comment
read replies to this comment
post reply to this comment
Comment by
jon
[Dec 26, 2005 @ 10:17 PM]
hi Nice code :)
read replies to this comment
post reply to this comment
Comment by
khirod kumar
[Mar 17, 2006 @ 3:51 AM]
hi,
Very good source.
read replies to this comment
post reply to this comment
Comment by
Mahmoud Tahoon
[May 14, 2006 @ 2:53 AM]
your code is just great, it did help me .. thank you very much.
read replies to this comment
post reply to this comment
Comment by
Shah bhavik
[Dec 19, 2006 @ 10:27 PM]
I understand your src code. but In the src code Refresh1 is defined and it is used in the binary file.
so please give me the proper source code.
Your code is great.
Thanks
read replies to this comment
post reply to this comment
Comment by
rishi
[Jan 15, 2007 @ 2:05 AM]
My contact form now detects browser refresh to eliminate multiple submissions.
here hyper link on "contact form" is not working
read replies to this comment
post reply to this comment
Comment by
Tester
[Feb 04, 2007 @ 11:22 PM]
There is a but with this code. When you first come to this page, click on the "Clicke Me" button to so the button status is "..clicked 1 times".
Now leave this page by using the navigation to the left (click on the cookie detection link). Once one the cookie detection page, use the navigation again and click on the Refresh Dection link. Notice that when you return back to Refresh Dection page, it thinks the page was refreshed.
If this is not a bug, please let me know why this occurs.
read replies to this comment
post reply to this comment
Comment by
Amit
[Mar 01, 2007 @ 8:13 PM]
I have 8 pages in my application. Starting from 2nd page I have your control on each page to detect page refresh. However when the user navigates from 1st page to 2nd page, the property IsRefreshed of control is set to TRUE from the start. Is this a bug?
Thank you.
read replies to this comment
post reply to this comment
Comment by
Leendert Halter
[Jun 11, 2007 @ 1:36 AM]
Trying to install the Refresh control I encounter the following problem in VS2005 (working with VM ware):
1. SelectTools/Choose Toolbox Items menu
2. Select tab .NET Framework Components
3. browse and select Joel.Net.Refresh.dll yields error message:
"Invalid URI: The hostname could not be parsed". Why is this and what can I do to solve this?
The host name is: amsdc1-s-6133.europe.shell.com
read replies to this comment
post reply to this comment
Comment by
Aries
[Aug 13, 2007 @ 7:33 PM]
Hey, I found a bug here. Copy this URL: http://joel.net/code/refresh_capture.aspx and then click on any other link and browse away from this page. Once you are in a different page, paste the above URL and it will say: The page HAS been refreshed. I have a similar problem, can't seem to get away with it.
read replies to this comment
post reply to this comment
Comment by
Joseph Humphrey
[Sep 09, 2007 @ 8:33 PM]
Based on this example I have rewritten the code to work with ajax and can be used as a base page in the App_Code folder.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
/// <summary>
/// Summary description for DomPage
/// </summary>
public class DomPage : Page
{
bool _isrefresh = false;
string _tname = "__Ticket";
/// <summary>Increments ticket and checks the last ticket served. All the work is here.</summary>
public DomPage()
{
this.PreInit += new EventHandler(DomPage_PreInit);
}
void DomPage_PreInit(object sender, EventArgs e)
{
// Change null to 0 (prevents errors)
if (Session[_tname + "_LastServed"] == null || Request[_tname] == null) { Session[_tname + "_LastServed"] = 0; }
// Get current and last ticket served
int ticket = Convert.ToInt32(Request[_tname]) + 1;
int lastticket = Convert.ToInt32(Session[_tname + "_LastServed"]);
// Refresh detection
if (ticket > lastticket || (ticket == 0 && lastticket == 0))
Session[_tname + "_LastServed"] = ticket;
else
_isrefresh = true;
}
/// <summary>Outputs hidden field with ticket id.</summary>
/// <param name="output">Html Text Writer</param>
protected override void Render(HtmlTextWriter output)
{
//Checks if the page is using Ajax
if (ScriptManager.GetCurrent(this) != null)
ScriptManager.RegisterHiddenField(this, _tname, Session[_tname + "_LastServed"].ToString());
else
Page.ClientScript.RegisterHiddenField(_tname, Session[_tname + "_LastServed"].ToString());
base.Render(output);
}
/// <summary>Returns true if page has been refreshed, otherwise false.</summary>
public bool IsRefresh
{
get { return _isrefresh; }
}
}
read replies to this comment
post reply to this comment
Comment by
Joseph Humphrey
[Sep 09, 2007 @ 8:35 PM]
You may want to remove the html breaks.. The comment added those :)
read replies to this comment
post reply to this comment
Comment by
???
[Jul 03, 2008 @ 6:11 PM]
??????[url=http://www.hztyzs.cn]???[/url]???? ?? ????????????? ?? ?????_??????? ?? ?????_??????? ?? ??i???????? ?????a?????????????,??h?????[url=http://www.sjglj.com/cpzs_cpfl.asp]????????[/url]??(Beijing traveling),??????????????·,??????????????????·,??????????????·,????????????·,?????????????h???????[url=http://www.sjglj.com/cpzs_cpfl_juti_datu.asp?id=300]???????[/url]???????????ý???????????????????????????????????????????????????????????????????????????????[url=http://www.sabg.com.cn]?????[/url]???????????????????????????????????????????????????????????????????[url=http://www.sino-office.com]??¥????[/url]??????¥????????????¥??????????¥?????????????¥??????¥?????????????¥?????????[url=http://www.sino-office.com]??¥????[/url]???????????????????u?¥????,???j?¥????,?????¥??????????
read replies to this comment
post reply to this comment
Comment by
???????????????
[Jul 08, 2008 @ 11:05 PM]
??????????????????-[url=http://www.hzqs.com.cn/www/42/2008-01/794.html]???????????????[/url]??????,?????,?????,??????,???????????????????,???????????????????,???????????????????????????????? ????????????[url=http://www.hzqs.com.cn/www/42/2008/3142.html]??????????????? [/url]???????????????????? ??????????????????? ???????????l?????????????? ???š???????????????? ??????????????????? ??????????????????? ????????
???????????? ,??????????????? ??,[url=http://www.hzqs.com.cn/www/42/2008/3116.html]???????????? [/url]??,??????????????? ,??????????????? ,???,???[url=http://www.hzqs.com.cn/www/42/]?????????[/url]????,?????????????,??????,??????,????????????,???????????,????????????
???[url=http://www.hzqs.com.cn/www/42/2008-01/783.html]?????????????[/url]??????????????????????ID??IP, ??????????????????????I????? .... ?????????????g??. - ????????????????????????????????????g????w??ë???[url=http://www.hzqs.com.cn/www/2/2008-01/1080.html]?????????ô???? [/url]?????????????l????????ô???? ??????????l????????ô???? ???????????ô???? ???????????L??l????????ô???? ???????
read replies to this comment
Leave Your Comment
Name:
Email:
(gravatar enabled)
URL:
Comment:
or
Cancel
Leave a Comment