New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

ASP.NET Validators Support

In this article, you will learn how to integrate the native ASP.NET validation control with RadCheckBoxList.

As of the R1 2017 release, there is built-in support for the RequiredFieldValidator control. Older versions can be integrated with the CustomValidator control as an alternative solution (see Example 2).

Using RequiredFieldValidator

To use the RequiredFieldValidator, you just need to set the ControlToValidate property to the CheckBoxList's ID. This will trigger validation when the user submits and the validation control will validate against the SelectedItem property and return the appropriate validation result.

Example 1: Configuring RequiredFieldValidator control with CheckBoxList.

<telerik:RadCheckBoxList runat="server" ID="RadCheckBoxList1" AutoPostBack="false">
    <Items>
        <telerik:ButtonListItem Text="Option 1" Value="0" />
        <telerik:ButtonListItem Text="Option 2" Value="1" />
        <telerik:ButtonListItem Text="Option 3" Value="2" />
    </Items>
</telerik:RadCheckBoxList>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
    ControlToValidate="RadCheckBoxList1"
    ErrorMessage="Please choose at least one of the options displayed" />

Using CustomValidator

As an alternative to the RequiredFieldValidator, you can use CustomValidator and have your own logic that validates the CheckBoxList.

Example 2: Configuring CustomValidator control with CheckBoxList.

<telerik:RadCheckBoxList runat="server" ID="RadCheckBoxList1" AutoPostBack="false">
    <Items>
        <telerik:ButtonListItem Text="Option 1" Value="0" />
        <telerik:ButtonListItem Text="Option 2" Value="1" />
        <telerik:ButtonListItem Text="Option 3" Value="2" />
    </Items>
</telerik:RadCheckBoxList>

<asp:CustomValidator ID="CustomButtonListValidator" runat="server" 
    ErrorMessage="Please choose at least one of the options displayed"
    OnServerValidate="CustomButtonListValidator_ServerValidate" />
protected void CustomButtonListValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
    args.IsValid = (RadCheckBoxList1.SelectedIndex > -1);
}
Protected Sub CustomButtonListValidator_ServerValidate(source As Object, args As ServerValidateEventArgs)
    args.IsValid = (RadCheckBoxList1.SelectedIndex > -1)
End Sub

See Also

In this article