CheckBox Enable/Disable Button Control

Some super handy validation controls put together by Scot Mitchell fill the validation void in ASP.NET Web Forms for checkbox & checkbox list controls.

However he expanded on these controls to allow for easy enable/disable functionality for a button triggered by a checkbox. This sort of functionality is quite common with systems that require you to accept the terms and conditions before proceeding, to prevent you from proceeding the button to do so is disabled until you tick the box.

Set up a webpage with a standard checkbox and button control.

<asp:CheckBox Checked=”false” CssClass=”information_control” ID=”termsAndConditionsCB” Text=”I agree to the terms and conditions.” runat=”server” />

<asp:Button ID=”proceedNow” runat=”server” Text=”Proceed” onclick=”proceedNow_Click” CssClass=”proceed_button” Enabled=”false” />

Now, download the demo app Scott put together and place the skmValidators.dll in the root of the .rar file to you documents. I keep all extension .ddl files like this in libs folder in my documents (Documents\Visual Studio 2010\Libs).

Add the custom controls to your toolbox in Visual Studio and drop the CheckBoxValidator onto your page and fill out the info like this:

<asp:checkboxvalidator ID=”CheckBoxValidator1” runat=”server” ControlToValidate=”termsAndConditionsCB” Display=”None” AssociatedButtonControlId=”quoteMeNow” MustBeChecked=”true”></asp:checkboxvalidator> 

That was it, if my termsAndConditionsCB was not ticked my proceedNow button was disabled.

Resource: 4guysfromrolla.com

blog comments powered by Disqus