简体   繁体   中英

Custom validator is not firing

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;
}

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM