Return to the menu   Select another DES Module

Demonstrates the CheckStateValidator

The CheckStateValidator evaluates the mark within a checkbox or radio button. You can select whether the Condition allows a marked or unmarked button.

The Condition of this Validator, CheckStateCondition, is more frequently used than the Validator itself. The Enabler property often turns on a Validator based on the state of a checkbox or radio button. MultiConditionValidators often evaluate checkboxes and radio buttons as part of their logic.

If you want to evaluate a RadioButtonList or CheckBoxList control, use the RequiredListValidator or SelectedIndexValidator.

If you want to evaluate that at least one CheckBox or RadioButton control in different rows of a grid or Repeater, use the CountTrueConditionsValidator with CheckStateConditions in its Conditions property.

Specify the control to evaluate with the ControlIDToEvaluate property.

The Checked property determines what state the CheckBox or RadioButton’s Checked property must match to evaluate successfully.

RadioButtons only run their client-side ‘onclick’ event when clicked, not when they become unmarked as another radio button is marked. If you want this Condition to be evaluated when you unmark a radiobutton not specified with ControlIDToEvaluate, specify the other radiobuttons in ExtraControlsToRunThisAction.


Controls

CheckBox


RadioButtons

Adds a ControlConnection object to the ExtraControlsToRunThisAction that points to the other radiobutton.



Source Code (C#)

<script runat="server">
protected void Button1_Click(object sender, EventArgs e) { if (PeterBlum.DES.Globals.WebFormDirector.IsValid) { // save your data here } }
</script> <h2>CheckBox</h2> <asp:CheckBox ID="CheckBox1" runat="Server" Text="I agree to the terms"/> <des:CheckStateValidator ID="CheckStateValidator2" runat="server" ControlIDToEvaluate="CheckBox1" ErrorMessage="Please mark the checkbox to indicate your acceptance of the terms." /> <br/> <h2>RadioButtons</h2> Adds a ControlConnection object to the ExtraControlsToRunThisAction that points to the other radiobutton.<br/> <asp:RadioButton ID="RadioButton1" runat="Server" GroupName="1" Text="1" Checked="true" /> <asp:RadioButton ID="RadioButton2" runat="Server" GroupName="1" Text="2" Checked="false" /> <des:CheckStateValidator ID="CheckStateValidator1" runat="server" ControlIDToEvaluate="RadioButton1" ErrorMessage="Select '1'"> <ExtraControlsToRunThisAction> <des:ControlConnection ControlID="RadioButton2" /> </ExtraControlsToRunThisAction> </des:CheckStateValidator> <br/> <br/> <des:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click"></des:Button>

Return to the menu   Select another DES Module