I am validating a checkbox list using custom validator and jquery to check required validation, its validating fine but its not getting focus on error.
the asp.net for CheckBoxList and CustomValidator is :
<asp:CheckBoxList ID="cblSellerCategories"
runat="server"
RepeatDirection="Horizontal">
</asp:CheckBoxList>
<asp:CustomValidator ID="CustomValidator2"
runat="server"
ClientValidationFunction="CheckSellerCategory"
CssClass="errorBox"
ErrorMessage="Select seller type"
SetFocusOnError="True">
</asp:CustomValidator>
and Jquery is
function CheckSellerCategory(sender, args) {
args.IsValid = false;
$("[id$='cblSellerCategories']").find(":checkbox").each(function () {
if (jQuery(this).attr("checked")) {
args.IsValid = true;
return;
}
});
}
How to get focus on error(if any check box is not selected). I tried with validation group as well but no luck.
If
SetFocusOnErroris not working you could set the focus manually doing something like thisSo your code would be