Data Cogs Information Technology

posts - 137, comments - 144, trackbacks - 42

General

Search This Site

Powered by Google

Brisbane

Locations of visitors to this page

Archives

How many times have you seen the problem where somebody clicks on the Submit button a hundred times?  One technique to avoid multiple submissions is to use client side script to disable the button after it has been clicked.  Problem is you only want to disable the button if the form is valid and is actually going to PostBack.  To get around this call the client side function Page_ClientValidate() to see if the page is valid.  If it is you can set a caption on the button, like “Please Wait...“, disable it, and invoke its click event,  like in the following code sample:

System.Text.StringBuilder sbValid = new System.Text.StringBuilder();

sbValid.Append("if (typeof(Page_ClientValidate) == 'function') { ");

sbValid.Append("if (Page_ClientValidate() == false) { return false; }} ");

sbValid.Append("this.value = 'Please wait...';");

sbValid.Append("this.disabled = true;");

sbValid.Append("document.all.btnSubmit.disabled = true;");

//GetPostBackEventReference obtains a reference to a client-side script function that causes the server to post back to the page.

sbValid.Append(this.Page.GetPostBackEventReference(this.btnSubmit));

sbValid.Append(";");

this.btnSubmit.Attributes.Add("onclick", sbValid.ToString());

posted on Wednesday, December 22, 2004 2:23 PM

Feedback

# Disable Button On PostBack (ASP.NET) - also works with validation controls (from: Mark Daunt)

12/24/2004 2:29 PM | TOURNEY LOGIC LINK BLOG

# Two Utility Functions

12/24/2004 3:24 PM | JOEL'S BLOG

# Two Utility Functions

12/24/2004 3:24 PM | Joel's Virtual Desktop

# Two Utility Functions

12/24/2004 3:24 PM | Joel Ross

# Disable Button On PostBack (ASP.NET) - also works with validation controls

12/24/2004 10:25 PM | Angus Logan

# Thanks Clayton

Thanks To Clayton James for providing this code sample.
12/30/2004 9:16 AM | Mark Daunt

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

Just what I was looking for.

Here is whole thing in one line of code.

btnBack.Attributes.Add("onclick", GetPostBackEventReference(btnBack) & ";this.value='Please wait...';this.disabled = true;")

Works perfectly!
3/24/2007 8:34 PM | secure email

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

Hello, Here I have found a lot of interesting. thanks
11/16/2007 10:10 PM | mapquest usa

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

If you are looking for the replica watch and information about it, you came to the right place.
12/25/2007 7:25 AM | Replica Watch

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

this.disabled = true;

the above will not call the _click server side event for the button... Just check it. So you can use this.style.display = 'none'; for same.

Thanks
JD
1/2/2008 2:33 AM | Free ebooks

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

This is the code that Visual Web Developer 2008 accepted

this.buttonReset.Attributes.Add("onclick", this.Page.ClientScript.GetPostBackEventReference(buttonReset,";this.value='Please wait...';this.disabled = true;"));

Here is the html that is generated

<input type="submit" name="buttonReset" value="Reset" onclick="__doPostBack('buttonReset',';this.value=\'Please wait...\';this.disabled = true;');" id="buttonReset" />

I click once and nothing
I clic twice and i get an javascript error and the following portion of the html code is highlighted

__doPostBack('buttonReset',';this.value=\'Please wait...\';this.disabled = true;');" id="buttonReset" />

Please advise
6/17/2008 7:36 AM | John

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

John,

change your code to this:

this.buttonReset.Attributes.Add("onclick", this.Page.ClientScript.GetPostBackEventReference(buttonReset, String.Empty) + ";this.value='Please wait...';this.disabled = true;");

that should sort you
6/17/2008 4:25 PM | cottsak

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

Blood rushing to the nipples. That’s exactly how Carly Cooper felt when she saw Nick. No, I mean Doug. Wait a minute, wasn’t it Joe? No, it’s Sam!! Or was it Phil?

Meet Carly Cooper, a 31 year old single woman who is totally depressed about the desperate state of her love life. Having been engaged no fewer than four times, she veers from http://karkode.com/index.php?sm=1
http://alfastok.com
http://mistoru.com/index.php?sm=3 relationship to relationship in search of Mr. Perfect, always optimistic that the next man will be The One.

Well, always optimistic until now, that is anime .
7/18/2008 6:47 PM | ralfir

# re: Disable Button On PostBack (ASP.NET) - also works with validation controls

Having taken stock of her life, she has made the momentous decision to look for the men of her past in search of true love. “Perhaps my True Love has been there all along but I didn’t realize it?”

So, what to do next? Ahh yes, quit the job and travel around the world in search of the men from her past and perhaps find true love.

Did she find her True Love hentai ?

Well, that’s something you have to find out for yourself when you read this book!!

I find the book an entertaining light reading material – what I would classify as a flight book. You know, the type of book that you pick up at the airport while waiting for the flight, the type of book that you read during the flight when you get bored with the on-flight entertainment. http://karkode.com/index.php?sm=2
http://vistorg.com/index.php?sm=2
http://alfastok.com/index.php?sm=3 After the flight, you chuck the book somewhere and forget all about it. At least, until you get bored again and there’s nothing better to read.

Not exactly the type of book that you will read over and over again, trying to grasp the hidden nuances that you miss during the first reading. But still entertaining enough. If manga you have nothing better to do, why not give it a try?
7/18/2008 6:47 PM | vistorg

Post Comment

Title  
Name  
Url
Comment   
Protected by Clearscreen.SharpHIPEnter the code you see: