Disable Buttons after click

Posted on: Thu Sep 25 16:57:33 -0700 2008. Updated on: Thu Sep 25 17:09:25 -0700 2008.
Category: Asp .Net AJAX / Javascript / CSS

When we have forms being submitted that record something to the Database, it is often a good idea to disable the buttons after the first click.

First add the following code to your header. If you are using master pages, this goes in the masterpage.


Then, in your code behind you will need to add an onclick attribute to the buttons you want to disable

CheckoutButton.Attributes.Add("onclick", "javascript:if(submitFlag){return false;}else{submitFlag = true; return true;}");

Note that on the onclick attribute you could also do something like $get('buttonClientId').Enabled = false . If you use master pages be sure you are using the right clientId for the button.

Comments:

Thu Feb 26 17:57:16 -0800 2009
ButtonContinue.Attributes.Add("onclick", "document.forms[0].ButtonContinue.disabled = true;");


---------------------------------------------------

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.