Daniel M. Hendricks

Using CustomValidator to Validate a Checkbox

If you’ve ever tried to use the RequiredFieldValidator on a CheckBox control in ASP.NET, you’ve probably seen the following error:

Control … referenced by the ControlToValidate property of … cannot be validated.

Since there is no built-in validator for the CheckBox control, we have to custom make one. This would apply to the CheckBoxList as well.

Server-Side Validation

Below is an example of confirming whether a checkbox has been checked on the server-side.

<%@ Page Language="C#" %>





I agree to the terms.

Client-side Validation

Below is an example of confirming whether a checkbox has been checked using client-side code.

<%@ Page Language="C#" %>








I agree to the terms.

One Response to “Using CustomValidator to Validate a Checkbox”

  1. whn i m using custom validator for checkbox and try to check whethe it is checked or not.. it gives me error like…

    “Control ‘chkTermServices’ referenced by the ControlToValidate property of ‘cvTermServices’ cannot be validated”

    i hv written following code..

    function checkTermsServices(source, args)
    {
    args.IsValid = document.getElementById(“”).checked;
    }

    where i m wrong ? do u any idea.. thn let me know abt cause of error…

    Happy Programming

    Sandeep Ramani

Post a Comment

You must be logged in to post a comment.

Tip: Sign up for a free Gravatar to have a photo next to your comment! Your gravatar will follow you around when you post to blogs that support it, based on the e-mail address you use to post.