![]() |
Web Development »
ASP.NET »
General
Intermediate
.NET implementation of the SynchronizerToken patternBy Fred WangAn article on resolving the issue of unintentional web form resubmission. |
C#, Windows, .NET 1.1, ASP.NET, WinForms, WebForms, VS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Joe was doing online shopping, he clicked the Submit button to place an order, there was no response for 5 seconds, he thought something had gone wrong and clicked the button again!
What happened?
Joe probably got charged twice!! It was only because he could not receive the response for whatever reason, but the sever got two requests from him and placed duplicate orders for him.
Here is a solution which can prevent such kind of mistakes.
Basically, this is a .NET implementation of the SynchronizerToken pattern which has been used in the Java world for years (refer to Core J2EE Patterns).
It is pretty easy to use:
SynchronizerToken assembly in your project.
Synchronizer page.
[OneSubmitOnly] attribute right before your page class. // Default message will be shown when duplicated
// submission happened if no RedirectURL property set.
//[OneSubmitOnly]
// Request will be redirected to ErrorPaga.aspx
// when duplicated submission happened.
[OneSubmitOnly(RedirectURL = "~/ErrorPage.aspx")]
public class WebForm1 : Synchronizer
{
.......
}
OneSumbmitOnly attribute has an optional RedirectURL property which points to any valid URL to where a request gets redirected when duplicated submission happens. If no RedirectURL property is set, the request gets rejected and the default message will show up.
Found a way to make resubmission check happen before any subclass event happens by overriding the OnLoad event handler. Now there is no worry about silly things happening in the subclass' Page_OnLoad method before the resubmission check.
| You must Sign In to use this message board. | |||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 7 Oct 2005 Editor: Smitha Vijayan |
Copyright 2005 by Fred Wang Everything else Copyright © CodeProject, 1999-2009 Web10 | Advertise on the Code Project |