Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 39237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:50:00+00:00 2026-05-10T14:50:00+00:00

I have a button that I would like to disable when the form submits

  • 0

I have a button that I would like to disable when the form submits to prevent the user submitting multiple times.

I have tried naively disabling the button with javascript onclick but then if a client side validation that fails the button remains disabled.

How do I disable the button when the form successfully submits not just when the user clicks?

This is an ASP.NET form so I would like to hook in nicely with the asp.net ajax page lifecycle if possible.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:50:01+00:00Added an answer on May 10, 2026 at 2:50 pm

    Give this a whirl:

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Threading;  public partial class _Default : System.Web.UI.Page  {     protected void Page_Load(object sender, EventArgs e)     {           // Identify button as a 'disabled-when-clicked' button...          WebHelpers.DisableButtonOnClick( buttonTest, 'showPleaseWait' );      }      protected void buttonTest_Click( object sender, EventArgs e )     {         // Emulate a server-side process to demo the disabled button during         // postback.         Thread.Sleep( 5000 );     } }    using System; using System.Web; using System.Web.UI.WebControls; using System.Text;  public class WebHelpers {     //     // Disable button with no secondary JavaScript function call.     //     public static void DisableButtonOnClick( Button ButtonControl )     {         DisableButtonOnClick( ButtonControl, string.Empty );         }      //     // Disable button with a JavaScript function call.     //     public static void DisableButtonOnClick( Button ButtonControl, string ClientFunction )     {            StringBuilder sb = new StringBuilder( 128 );          // If the page has ASP.NET validators on it, this code ensures the         // page validates before continuing.         sb.Append( 'if ( typeof( Page_ClientValidate ) == 'function' ) { ' );         sb.Append( 'if ( ! Page_ClientValidate() ) { return false; } } ' );          // Disable this button.         sb.Append( 'this.disabled = true;' );           // If a secondary JavaScript function has been provided, and if it can be found,         // call it. Note the name of the JavaScript function to call should be passed without         // parens.         if ( ! String.IsNullOrEmpty( ClientFunction ) )          {             sb.AppendFormat( 'if ( typeof( {0} ) == 'function' ) {{ {0}() }};', ClientFunction );           }          // GetPostBackEventReference() obtains a reference to a client-side script function          // that causes the server to post back to the page (ie this causes the server-side part          // of the 'click' to be performed).         sb.Append( ButtonControl.Page.ClientScript.GetPostBackEventReference( ButtonControl ) + ';' );          // Add the JavaScript created a code to be executed when the button is clicked.         ButtonControl.Attributes.Add( 'onclick', sb.ToString() );     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 92k
  • Answers 92k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Something like a Mersenne Twister (from Boost.Random) is deterministic. May 11, 2026 at 6:30 pm
  • Editorial Team
    Editorial Team added an answer You simply delete the .egg file On OS X they… May 11, 2026 at 6:30 pm
  • Editorial Team
    Editorial Team added an answer An auto-increment field in MySQL must be part of a… May 11, 2026 at 6:30 pm

Related Questions

Is it possible to disable a button in a DataGridTemplateColumn? I have a DataGridTemplate
I have a window (derived from JFrame) and I want to disable the close
I have a UISearchBar and on the delegate method I hide the keyboard when
I had a bunch of controls that I displayed, hid, enabled and disabled based

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.