Scott,
If you have tried the RequiredFieldValidator, you would have seen:
Control 'chk' referenced by the ControlToValidate property of
'RequiredFieldValidator1' cannot be validated.
Indeed, the built-in validator controls cannot validate the checkbox. You
will have to use the custom validator to do this or write your own client
side validation.
A quick search of Google for "asp.net validate checkbox", you would find
that one of the results is:
http://msdn.microsoft.com/library/de...ercontrols.asp,
and this explains how validations work.
Here's a page that validates a checkbox:
<%@ Page language="c#" Codebehind="ValidateCheckbox.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication1.ValidateCheckbox" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<script language="javascript">
function ValidateChecked(oSrc, args){
if(document.all["<%=chk.ClientID%>"].checked == false){
alert("Has to be checked.");
args.IsValid = false;
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:CustomValidator ClientValidationFunction="ValidateChecked"
Runat="server" ID="val"/>
<asp:CheckBox ID="chk" Runat="server" />
<asp:Button ID="btn" Runat="server" Text="Submit" />
</form>
</body>
</HTML>
Best regards,
Jeffrey Palermo
"Scott Natwick" <no**********@yahoo.com> wrote in message
news:i4********************@comcast.com...
I would like to validate that a Checkbox is checked on the client-side.
I have tried the "requiredfieldvalidator" and the
"regularexpressionvalidator", but haven't been able to get either of them
to work the Checkbox.
Any suggestions?
Thanks,
Scott