required field validator not working for checkbox.

G

Guest

greetings

i want to use the required field validator control to validate a checkbox.
here is the code implemented.

<asp:RequiredFieldValidator ID="rfv" ControlToValidate="chkDistiAudit"
ErrorMessage="error" runat="server" />

<asp:checkbox id="chkDistiAudit" runat="server" CssClass="objControl_left"
Width="100px" Text="Disti Audit" Checked="True"></asp:checkbox>

and below is the error return

Control 'chkDistiAudit' referenced by the ControlToValidate property of
'rfv' cannot be validated.

can somone please help me out here?.
thanks...
 
G

Guest

I question your desire to use it on a checkbox. A checkbox has two valid
values, checked and unchecked. Each is valid. From a user-interface-design
perspective, perhaps you should use a different type of input.
 
P

Peter Blum

Simply put, Checkboxes are not supported by the predefined validators. You
can write your own code with a CustomValidator to detect the state of the
checkbox and report an error.

My replacement to Microsoft's validators, Professional Validation and More
(http://www.peterblum.com/vam/home.aspx) includes a CheckStateValidator for
checkboxes and radiobuttons amongst the 22 validators it offers. I wrote
Professional Validation And More after finding numerous limitations in
Microsoft's validators that required custom coding and creative hacks to
resolve. I put together a list of the limitations that I've found here:
http://www.peterblum.com/vam/valmain.aspx.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top