473,609 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Preventing second click of a button

I have an ASP.NET 2 page with a button that causes a credit card transaction
to be authorised. The authorisation procedure may take a few seconds and so
I want to prevent the user from clicking the button again (or at least
detect that an authorisation is already in progress and do nothing) while
the first authorisation is in progress. Can someone help me out?

I've tried the following but none of the solutions work:
1) Disabling the button via JavaScript when it is clicked. This prevents the
server-side event from firing.
2) Disabling the button via JavaScript when it is clicked and calling
doPostback. This just causes an 'Object Expected' error. (I have fully
qualified the button's Id as the first parameter passed to doPostback.)
3) Disabling the button in the server-side Click event. The button is not
disabled until the Click event is finished. (i.e. After the authorisation)

Oct 10 '08 #1
2 2805

You can fish through this for some ideas:

YouHaveToFigure Out
means that I had a helper library do to this, you'll have to infer what I
did.
They should be intuitive.


private static readonly string HREF_ALREADY_CL ICKED_VARIABLE_ NAME =
"hrefAlreadyCli cked";
private static readonly string
HREF_ALREADY_CL ICKED_VARIABLE_ NAME_JS_KEY =
"HREF_ALREADY_C LICKED_VARIABLE _NAME_JS_KEY";
private static readonly string JS_INDENT = " ";


/// <summary>
/// Provides the double submit prevention on controls issuing a
PostBack.
/// </summary>
/// <param name="TargetPag e">The target page.</param>
/// <param name="c">The control.</param>
public static void DoubleSubmitPre vention(Page TargetPage,
System.Web.UI.W ebControls.WebC ontrol c)
{
DoubleSubmitPre vention(TargetP age, c, string.Empty);
}
/// <summary>
/// Doubles the submit prevention.
/// </summary>
/// <param name="TargetPag e">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitIma geName">Name of the submit image.</param>
public static void DoubleSubmitPre vention(Page TargetPage,
System.Web.UI.W ebControls.WebC ontrol c, string submitImageName )
{
DoubleSubmitPre vention(TargetP age, c, submitImageName , 125);// a
125 milliseconds delay seems to be a good balance
}
/// <summary>
/// Provides the double submit prevention on controls issuing a
PostBack.
/// </summary>
/// <param name="TargetPag e">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitIma geName">Name of the alternate image to
show while the PostBack is occuring.</param>
/// <param name="imageDela yMilliseconds"> The image delay
milliseconds. Suggested value is around 125.</param>
public static void DoubleSubmitPre vention(Page TargetPage,
System.Web.UI.W ebControls.WebC ontrol c, string submitImageName , int
imageDelayMilli seconds)
{

string wcUID = c.ID;
// We need a member variable to track this.......so register it
here
YouHaveToFigure OutRegisterGene ricJavaScriptBl ock(TargetPage,
"var " + HREF_ALREADY_CL ICKED_VARIABLE_ NAME + "=false;",
HREF_ALREADY_CL ICKED_VARIABLE_ NAME_JS_KEY, true);

string pleaseWait = "Please Wait...";

System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
if (TargetPage.Val idators.Count 0)
{
sb.Append("if (typeof(Page_Cl ientValidate) == 'function')
{ ");
sb.Append("if (Page_ClientVal idate() == false) { return
false; }} ");
}
if ((c is System.Web.UI.W ebControls.Butt on))
{
sb.Append("this .value = '" + pleaseWait + "';");
}
else if ((c is System.Web.UI.W ebControls.Link Button))
{
sb.Append("this .innerHTML = '" + pleaseWait +
"';if(hrefAlrea dyClicked==fals e){" + HREF_ALREADY_CL ICKED_VARIABLE_ NAME +
"=true;retu rn true;}else{this .innerHTML+='.. .';return false;};");
}
else if ((c is System.Web.UI.W ebControls.Imag eButton))
{
YouHaveToFigure OutRegisterGene ricJavaScriptBl ock(TargetPage,
"var imgSaveButtonAl ternate = new Image().src = '" + submitImageName + "'",
"ImagePreLo ad", true);
sb.Append("this .src = '" + submitImageName + "';");
sb.Append("setT imeout('" +
TargetPage.Clie ntScript.GetPos tBackEventRefer ence(c , null).Replace(" '",
"\\'") + ";', " + imageDelayMilli seconds + ");");
}
else
{
throw new ArgumentExcepti on("This procedure only accepts '
System.Web.UI.W ebControls.Butt on', 'System.Web.UI. WebControls.Lin kButton' ,
and ' System.Web.UI.W ebControls.Imag eButton' objects");
}
sb.Append("this .disabled=true; ");
if (!((c is System.Web.UI.W ebControls.Imag eButton)))
{
sb.Append(Targe tPage.ClientScr ipt.GetPostBack EventReference( c,
null));
}
sb.Append(";");
YouHaveToFigure OutAppendAttrib ute(c, "onClick", sb.ToString());
sb = null;
}


"chrisp" <ch**********@n ospam.co.ukwrot e in message
news:ui******** ******@TK2MSFTN GP06.phx.gbl...
>I have an ASP.NET 2 page with a button that causes a credit card
transaction to be authorised. The authorisation procedure may take a few
seconds and so I want to prevent the user from clicking the button again
(or at least detect that an authorisation is already in progress and do
nothing) while the first authorisation is in progress. Can someone help me
out?

I've tried the following but none of the solutions work:
1) Disabling the button via JavaScript when it is clicked. This prevents
the server-side event from firing.
2) Disabling the button via JavaScript when it is clicked and calling
doPostback. This just causes an 'Object Expected' error. (I have fully
qualified the button's Id as the first parameter passed to doPostback.)
3) Disabling the button in the server-side Click event. The button is not
disabled until the Click event is finished. (i.e. After the authorisation)

Oct 10 '08 #2
this only handles double click only, not refresh, or refresh and click, or
back from the next page.

you should assign a transaction guid, and put it in a hidden field on
render. on postback, check if the guid has been processed, if so error, else
process and log as processed.

-- bruce (sqlwork.com)
"sloan" wrote:
>
You can fish through this for some ideas:

YouHaveToFigure Out
means that I had a helper library do to this, you'll have to infer what I
did.
They should be intuitive.


private static readonly string HREF_ALREADY_CL ICKED_VARIABLE_ NAME =
"hrefAlreadyCli cked";
private static readonly string
HREF_ALREADY_CL ICKED_VARIABLE_ NAME_JS_KEY =
"HREF_ALREADY_C LICKED_VARIABLE _NAME_JS_KEY";
private static readonly string JS_INDENT = " ";


/// <summary>
/// Provides the double submit prevention on controls issuing a
PostBack.
/// </summary>
/// <param name="TargetPag e">The target page.</param>
/// <param name="c">The control.</param>
public static void DoubleSubmitPre vention(Page TargetPage,
System.Web.UI.W ebControls.WebC ontrol c)
{
DoubleSubmitPre vention(TargetP age, c, string.Empty);
}
/// <summary>
/// Doubles the submit prevention.
/// </summary>
/// <param name="TargetPag e">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitIma geName">Name of the submit image.</param>
public static void DoubleSubmitPre vention(Page TargetPage,
System.Web.UI.W ebControls.WebC ontrol c, string submitImageName )
{
DoubleSubmitPre vention(TargetP age, c, submitImageName , 125);// a
125 milliseconds delay seems to be a good balance
}
/// <summary>
/// Provides the double submit prevention on controls issuing a
PostBack.
/// </summary>
/// <param name="TargetPag e">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitIma geName">Name of the alternate image to
show while the PostBack is occuring.</param>
/// <param name="imageDela yMilliseconds"> The image delay
milliseconds. Suggested value is around 125.</param>
public static void DoubleSubmitPre vention(Page TargetPage,
System.Web.UI.W ebControls.WebC ontrol c, string submitImageName , int
imageDelayMilli seconds)
{

string wcUID = c.ID;
// We need a member variable to track this.......so register it
here
YouHaveToFigure OutRegisterGene ricJavaScriptBl ock(TargetPage,
"var " + HREF_ALREADY_CL ICKED_VARIABLE_ NAME + "=false;",
HREF_ALREADY_CL ICKED_VARIABLE_ NAME_JS_KEY, true);

string pleaseWait = "Please Wait...";

System.Text.Str ingBuilder sb = new System.Text.Str ingBuilder();
if (TargetPage.Val idators.Count 0)
{
sb.Append("if (typeof(Page_Cl ientValidate) == 'function')
{ ");
sb.Append("if (Page_ClientVal idate() == false) { return
false; }} ");
}
if ((c is System.Web.UI.W ebControls.Butt on))
{
sb.Append("this .value = '" + pleaseWait + "';");
}
else if ((c is System.Web.UI.W ebControls.Link Button))
{
sb.Append("this .innerHTML = '" + pleaseWait +
"';if(hrefAlrea dyClicked==fals e){" + HREF_ALREADY_CL ICKED_VARIABLE_ NAME +
"=true;retu rn true;}else{this .innerHTML+='.. .';return false;};");
}
else if ((c is System.Web.UI.W ebControls.Imag eButton))
{
YouHaveToFigure OutRegisterGene ricJavaScriptBl ock(TargetPage,
"var imgSaveButtonAl ternate = new Image().src = '" + submitImageName + "'",
"ImagePreLo ad", true);
sb.Append("this .src = '" + submitImageName + "';");
sb.Append("setT imeout('" +
TargetPage.Clie ntScript.GetPos tBackEventRefer ence(c , null).Replace(" '",
"\\'") + ";', " + imageDelayMilli seconds + ");");
}
else
{
throw new ArgumentExcepti on("This procedure only accepts '
System.Web.UI.W ebControls.Butt on', 'System.Web.UI. WebControls.Lin kButton' ,
and ' System.Web.UI.W ebControls.Imag eButton' objects");
}
sb.Append("this .disabled=true; ");
if (!((c is System.Web.UI.W ebControls.Imag eButton)))
{
sb.Append(Targe tPage.ClientScr ipt.GetPostBack EventReference( c,
null));
}
sb.Append(";");
YouHaveToFigure OutAppendAttrib ute(c, "onClick", sb.ToString());
sb = null;
}


"chrisp" <ch**********@n ospam.co.ukwrot e in message
news:ui******** ******@TK2MSFTN GP06.phx.gbl...
I have an ASP.NET 2 page with a button that causes a credit card
transaction to be authorised. The authorisation procedure may take a few
seconds and so I want to prevent the user from clicking the button again
(or at least detect that an authorisation is already in progress and do
nothing) while the first authorisation is in progress. Can someone help me
out?

I've tried the following but none of the solutions work:
1) Disabling the button via JavaScript when it is clicked. This prevents
the server-side event from firing.
2) Disabling the button via JavaScript when it is clicked and calling
doPostback. This just causes an 'Object Expected' error. (I have fully
qualified the button's Id as the first parameter passed to doPostback.)
3) Disabling the button in the server-side Click event. The button is not
disabled until the Click event is finished. (i.e. After the authorisation)



Oct 10 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
13095
by: Mark | last post by:
This is a solution... Often users want to keep clicking "submit" when they are waiting for server processing. Most apps these days like to disable the submit button to prevent this. You can't just disable the button in the OnClick event in ASP.Net because then the Click event won't post to the server (because you disabled it). I searched google groups, and there is a solution to this problem, but I didn't think it was clean enough and...
13
636
by: Oleg Konovalov | last post by:
Hi, I have a Java GUI application where I perform a lot of long DB operations , which takes 5-60 secs to perform. Sometimes user double-clicks the button or just gets impatient and clicks again, which created duplicate records. So I am trying to disable the button as soon as it is clicked, and as soon as it's done, re-enable it again.
3
2323
by: Jim in Arizona | last post by:
How can I prevent a second (or third or fourth) post into a database by someone clicking the refresh button on their browser? Basically, the user clicks a button called "New Log", which makes most of the form within a <div runat="server"to go invisible and another <divgo visible. This includes a text box and a save button. They type text into the textbox and click save, which executes a stored procedure that does the insert into an SQL...
0
8541
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8406
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5510
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4021
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2531
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1672
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1389
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.