//Client Site Event Handler to put in Page_Load event
Page.RegisterClientScriptBlock("ValidateCheckBox1","<SCRIPT
LANGUAGE=\"JavaScript\">function validateCheckBox1(oSrc, args){args.IsValid
= document.all[\""+ CheckBox1.ID +"\"].checked;}</SCRIPT>");
//Server Site Event Handler
private void CustomValidator1_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
if (CheckBox1.Checked)
args.IsValid=true;
else
args.IsValid=false;
}
//Page Controls
<td>
<p>
<asp:CheckBox id="CheckBox1" runat="server"
Checked="False"></asp:CheckBox><FONT color="#ff3333">*</FONT>Agree
to Terms
<asp:CustomValidator id="CustomValidator1"
ClientValidationFunction="validateCheckBox1" runat="server"
ErrorMessage="[Agree to Terms] must be
checked">[Required]</asp:CustomValidator>
</p>
</td>
document.all['CheckBox1'].checked <- returns true or false
You should follow the .net docs on CustomValidators to learn how to enclose
that code within a client-side function.
FYI: I have built a replacement to Microsoft's validators that overcomes its
numerous limitations. "Professional Validation And More"
(http://www.peterblum.com/vam/home.aspx) includes a CheckedStateValidator
amongst the 22 validators it has. All of them have client-side support and
work on more browsers than Microsoft's (MS is only IE; mine works on IE,
Netscape/Mozilla, Opera 7 and Safari).
--- Peter Blum
www.PeterBlum.com
Email: PLB...@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Earl Teigrob" <earl...@hotmail.com> wrote in message
news:eYEhE7P7...@TK2MSFTNGP12.phx.gbl...
Thanks for your feedback. Now am I missing something? I do have the follow
script to do the Client side validation that includes the
document.all['CheckBox1'].checked function you mention...
> Page.RegisterClientScriptBlock("ValidateCheckBox1","<SCRIPT
> LANGUAGE=\"JavaScript\">function validateCheckBox1(oSrc,
args){args.IsValid
> = document.all[\""+ CheckBox1.ID +"\"].checked;}</SCRIPT>");
I just wrote it out dynamically so I could set the CheckBox1 Id property.
I will certainly check out your validators you have written...they are a
pain to write from scratch every time...
Earl
"Peter Blum" <PLB...@Blum.info> wrote in message
news:Ody%23Rtb7D...@TK2MSFTNGP10.phx.gbl...
--- Peter Blum
www.PeterBlum.com
Email: PLB...@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
"Earl Teigrob" <earl...@hotmail.com> wrote in message
news:%23lJ7Ozs...@TK2MSFTNGP11.phx.gbl...