473,471 Members | 1,716 Online
Bytes | Software Development & Data Engineering Community
Create 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 2790

You can fish through this for some ideas:

YouHaveToFigureOut
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_CLICKED_VARIABLE_NAME =
"hrefAlreadyClicked";
private static readonly string
HREF_ALREADY_CLICKED_VARIABLE_NAME_JS_KEY =
"HREF_ALREADY_CLICKED_VARIABLE_NAME_JS_KEY";
private static readonly string JS_INDENT = " ";


/// <summary>
/// Provides the double submit prevention on controls issuing a
PostBack.
/// </summary>
/// <param name="TargetPage">The target page.</param>
/// <param name="c">The control.</param>
public static void DoubleSubmitPrevention(Page TargetPage,
System.Web.UI.WebControls.WebControl c)
{
DoubleSubmitPrevention(TargetPage, c, string.Empty);
}
/// <summary>
/// Doubles the submit prevention.
/// </summary>
/// <param name="TargetPage">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitImageName">Name of the submit image.</param>
public static void DoubleSubmitPrevention(Page TargetPage,
System.Web.UI.WebControls.WebControl c, string submitImageName)
{
DoubleSubmitPrevention(TargetPage, 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="TargetPage">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitImageName">Name of the alternate image to
show while the PostBack is occuring.</param>
/// <param name="imageDelayMilliseconds">The image delay
milliseconds. Suggested value is around 125.</param>
public static void DoubleSubmitPrevention(Page TargetPage,
System.Web.UI.WebControls.WebControl c, string submitImageName, int
imageDelayMilliseconds)
{

string wcUID = c.ID;
// We need a member variable to track this.......so register it
here
YouHaveToFigureOutRegisterGenericJavaScriptBlock(T argetPage,
"var " + HREF_ALREADY_CLICKED_VARIABLE_NAME + "=false;",
HREF_ALREADY_CLICKED_VARIABLE_NAME_JS_KEY, true);

string pleaseWait = "Please Wait...";

System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (TargetPage.Validators.Count 0)
{
sb.Append("if (typeof(Page_ClientValidate) == 'function')
{ ");
sb.Append("if (Page_ClientValidate() == false) { return
false; }} ");
}
if ((c is System.Web.UI.WebControls.Button))
{
sb.Append("this.value = '" + pleaseWait + "';");
}
else if ((c is System.Web.UI.WebControls.LinkButton))
{
sb.Append("this.innerHTML = '" + pleaseWait +
"';if(hrefAlreadyClicked==false){" + HREF_ALREADY_CLICKED_VARIABLE_NAME +
"=true;return true;}else{this.innerHTML+='...';return false;};");
}
else if ((c is System.Web.UI.WebControls.ImageButton))
{
YouHaveToFigureOutRegisterGenericJavaScriptBlock(T argetPage,
"var imgSaveButtonAlternate = new Image().src = '" + submitImageName + "'",
"ImagePreLoad", true);
sb.Append("this.src = '" + submitImageName + "';");
sb.Append("setTimeout('" +
TargetPage.ClientScript.GetPostBackEventReference( c , null).Replace("'",
"\\'") + ";', " + imageDelayMilliseconds + ");");
}
else
{
throw new ArgumentException("This procedure only accepts '
System.Web.UI.WebControls.Button', 'System.Web.UI.WebControls.LinkButton' ,
and ' System.Web.UI.WebControls.ImageButton' objects");
}
sb.Append("this.disabled=true;");
if (!((c is System.Web.UI.WebControls.ImageButton)))
{
sb.Append(TargetPage.ClientScript.GetPostBackEvent Reference(c,
null));
}
sb.Append(";");
YouHaveToFigureOutAppendAttribute(c, "onClick", sb.ToString());
sb = null;
}


"chrisp" <ch**********@nospam.co.ukwrote in message
news:ui**************@TK2MSFTNGP06.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:

YouHaveToFigureOut
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_CLICKED_VARIABLE_NAME =
"hrefAlreadyClicked";
private static readonly string
HREF_ALREADY_CLICKED_VARIABLE_NAME_JS_KEY =
"HREF_ALREADY_CLICKED_VARIABLE_NAME_JS_KEY";
private static readonly string JS_INDENT = " ";


/// <summary>
/// Provides the double submit prevention on controls issuing a
PostBack.
/// </summary>
/// <param name="TargetPage">The target page.</param>
/// <param name="c">The control.</param>
public static void DoubleSubmitPrevention(Page TargetPage,
System.Web.UI.WebControls.WebControl c)
{
DoubleSubmitPrevention(TargetPage, c, string.Empty);
}
/// <summary>
/// Doubles the submit prevention.
/// </summary>
/// <param name="TargetPage">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitImageName">Name of the submit image.</param>
public static void DoubleSubmitPrevention(Page TargetPage,
System.Web.UI.WebControls.WebControl c, string submitImageName)
{
DoubleSubmitPrevention(TargetPage, 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="TargetPage">The target page.</param>
/// <param name="c">The control which needs double submit
prevention. Button, LinkButton, or ImageButton.</param>
/// <param name="submitImageName">Name of the alternate image to
show while the PostBack is occuring.</param>
/// <param name="imageDelayMilliseconds">The image delay
milliseconds. Suggested value is around 125.</param>
public static void DoubleSubmitPrevention(Page TargetPage,
System.Web.UI.WebControls.WebControl c, string submitImageName, int
imageDelayMilliseconds)
{

string wcUID = c.ID;
// We need a member variable to track this.......so register it
here
YouHaveToFigureOutRegisterGenericJavaScriptBlock(T argetPage,
"var " + HREF_ALREADY_CLICKED_VARIABLE_NAME + "=false;",
HREF_ALREADY_CLICKED_VARIABLE_NAME_JS_KEY, true);

string pleaseWait = "Please Wait...";

System.Text.StringBuilder sb = new System.Text.StringBuilder();
if (TargetPage.Validators.Count 0)
{
sb.Append("if (typeof(Page_ClientValidate) == 'function')
{ ");
sb.Append("if (Page_ClientValidate() == false) { return
false; }} ");
}
if ((c is System.Web.UI.WebControls.Button))
{
sb.Append("this.value = '" + pleaseWait + "';");
}
else if ((c is System.Web.UI.WebControls.LinkButton))
{
sb.Append("this.innerHTML = '" + pleaseWait +
"';if(hrefAlreadyClicked==false){" + HREF_ALREADY_CLICKED_VARIABLE_NAME +
"=true;return true;}else{this.innerHTML+='...';return false;};");
}
else if ((c is System.Web.UI.WebControls.ImageButton))
{
YouHaveToFigureOutRegisterGenericJavaScriptBlock(T argetPage,
"var imgSaveButtonAlternate = new Image().src = '" + submitImageName + "'",
"ImagePreLoad", true);
sb.Append("this.src = '" + submitImageName + "';");
sb.Append("setTimeout('" +
TargetPage.ClientScript.GetPostBackEventReference( c , null).Replace("'",
"\\'") + ";', " + imageDelayMilliseconds + ");");
}
else
{
throw new ArgumentException("This procedure only accepts '
System.Web.UI.WebControls.Button', 'System.Web.UI.WebControls.LinkButton' ,
and ' System.Web.UI.WebControls.ImageButton' objects");
}
sb.Append("this.disabled=true;");
if (!((c is System.Web.UI.WebControls.ImageButton)))
{
sb.Append(TargetPage.ClientScript.GetPostBackEvent Reference(c,
null));
}
sb.Append(";");
YouHaveToFigureOutAppendAttribute(c, "onClick", sb.ToString());
sb = null;
}


"chrisp" <ch**********@nospam.co.ukwrote in message
news:ui**************@TK2MSFTNGP06.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
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...
13
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...
3
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.