Reputation: 1898
I have a gridview called gv1
. There is checkbox inside it, and atleast 1 checkbox must be checked for processing. I have custom validation for it but it is not working. Please take a look at below,
Custom Validator
<asp:CustomValidator runat="server" ID="vldItemCus"
ClientValidationFunction="ValidateSelection"
Display="None" ErrorMessage="Select atleast 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;
}
Upvotes: 0
Views: 174
Reputation: 1898
Changed function as below,
function ValidateSelection(source, args) {
var found = 0;
$('#<%= gv1.ClientID %> input[type=checkbox]').each(function () {
if (this.checked) {
found = 1;
return false;
}
});
if (found == 1) {
args.IsValid = true;
}
else {
args.IsValid = false;
}
return;
}
Upvotes: 1