My 2c, easily done via the AJAX client library. I use the following code for 
cancelling button clicks during an async postback (ie inside an Update Panel)
(Note the client library is only available if you have a scriptmanager control 
on your form)

-Add the following javascript to your page
 function pageLoad() {
            
Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(cancelPostBack);

        }

        function cancelPostBack(sender, args) {
            if 
(Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack()) 
{            

                args.set_cancel(true); //cancels any clicks if we are already 
processing one
            }
        }   


IMHO the value in doing this on the client rather than server side is the 
reduction in traffic between client and server.

Jamie




________________________________
From: Richard Carde <rich...@carde.id.au>
To: ozDotNet <ozdotnet@ozdotnet.com>
Sent: Wed, 20 April, 2011 13:42:59
Subject: Re: add code to all button on my asp.net website?


Anthony

I presume you're trying to disable the button so a user cannot click twice.

This methodology has been discussed previously and, assuming that's the case, 
you're looking at the problem the wrong way around.  This is similar to the 
'how 
do I disable the back button' question.

What do you do if there's a s script error or network glitch during the POST. 
 The user is stuck.

Let the user click as many times as they want or go back and forth - just make 
sure you process the request once.  Do this by inserting a nonce into the form 
as a hidden item and store it in the DB or session state. When you've processed 
it, mark it as such and move the user on - a GUID is often used for this 
purpose.

Job done!  No jiggery-pokery on the client side where you have less control.

Good luck, and do let us know the site you're working on if it goes public.

--
Richard Carde

On 19 Apr 2011, at 03:28, "Anthony" <asale...@tpg.com.au> wrote:


I want add the following to all button on my website  i.e. 
button.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(button, 
"") + ";this.value='Processing Credit Card Payment...';this.disabled = true;")

> 
>Is there an easy to automatically apply this to all buttons?
> 
>regards
>Anthony (*12QWERNB*)
> 
> 

Reply via email to