One of the challenges I faced was with a gridview named gv1
. It contains checkboxes, and at least one checkbox must be checked for processing. Despite having custom validation in place, it seems to not be functioning correctly. Below is an overview:
The Custom Validator configuration:
<asp:CustomValidator runat="server" ID="vldItemCus"
ClientValidationFunction="ValidateSelection"
Display="None" ErrorMessage="Select at least one item for update" ValidationGroup="Update"></asp:CustomValidator>
Validation Summary:
<asp:ValidationSummary ID="vldSummary" runat="server" ShowMessageBox="True" ShowSummary="False" ValidationGroup="Update"></asp:ValidationSummary>
Javascript Function:
function ValidateSelection(source, args) {
var found = 0;
$('#gv1 input[type=checkbox]').each(function () {
if (this.checked) {
found = 1;
return false;
}
});
if (found == 1) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
return;
}