I am trying to do client side custom validation. I have the following code in my aspx page, but I keep getting an error saying
System.Web.HttpException (0x80004005): Control ‘chkList_Counts’
referenced by the ControlToValidate property of ‘validationCheck’
cannot be validated. at
System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String
name, String propertyName) at
System.Web.UI.WebControls.CustomValidator.ControlPropertiesValid() at
System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) at
System.Web.UI.Control.PreRenderRecursiveInternal() at
I cannot even see my page. I get the error right away before the page displays.
Below is my code
<div>
<asp:Panel ID="panel3" runat="server" CssClass="cis_edit_pnl"
GroupingText="Counts" Width="1240px">
<asp:CheckBoxList ID="chkList_Counts" runat="server"
RepeatDirection="Horizontal"
RepeatColumns="3" Width="1060px">
</asp:CheckBoxList>
<asp:CustomValidator ID="validationCheck" runat="server" ControlToValidate="chkList_Counts" ClientValidationFunction="check_checkBoxList" EnableClientScript="true" ErrorMessage="At least one of the check boxes should be checked">
</asp:CustomValidator>
</asp:Panel>
</div>
and my javascript function is like this
function check_checkBoxList(sender, args) {
debugger;
if (check_Counts() == false) {
args.IsValid = false;
return;
}
args.IsValid = true;
return;
}
function check_casrepCounts() {
var control;
control = document.getElementById("<%=chkList_Counts.ClientID %>").getElementsByTagName("input");
if (eval(control)) {
for (var i = 0; i < control.length; i++) {
if (control[i].checked == true)
return true;
}
return false;
}
}
Thanks in advance.
It works fine now, I just had to remove controlToValidate and it worked.