Page_ClientValidate() with multiple ValidationGroups - how to show multiple summaries simultaneously?

后端 未结 6 1364
予麋鹿
予麋鹿 2020-12-01 04:31

ASP.NET 2.0. Lets say i have two Validation Groups valGrpOne and valGrpTwo; and two Validation Summaries valSummOne and valSummTwo; Reason for breaking up sections is purely

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 05:25

    Here is another simple and generic method for validating against multiple groups.

    // Page_ClientValidate only shows errors from the last validation group.  
    // This method allows showing for multiple groups
    function Page_ClientValidateMultiple(groups) {
        var invalidIdxs = [];
        var result = true;
    
        // run validation from each group and remember failures
        for (var g = 0; g < groups.length; g++) {
            result = Page_ClientValidate(groups[g]) && result;
            for (var v = 0; v < Page_Validators.length; v++)
                if (!Page_Validators[v].isvalid)
                    invalidIdxs.push(v);
        }
    
        // re-show any failures
        for (var i = 0; i < invalidIdxs.length; i++) {
            ValidatorValidate(Page_Validators[invalidIdxs[i]]);
        }
    
        // return false if any of the groups failed
        return result;
    };
    

提交回复
热议问题