Elegant way to combine ASP.NET validation with JQuery

前端 未结 3 1280
误落风尘
误落风尘 2021-02-02 18:41

How can I best combine JQuery with ASP.NET client side validation model?

I\'ve generally avoided implementing ASP.NET validation model because it always seems overkill f

3条回答
  •  清酒与你
    2021-02-02 19:08

    ASP.NET validator is a span with additional attributes. With jquery you can acces all validators on the page or filter they by any criteria supported by jquery. To force validation via javascript call ValidatorValidate function. For example:

    function validate_step(step_element) {
            // find all validators on step_element and force validation
            var validators = $(step_element).find("span[controltovalidate]");
            var stepIsValid = true;
            validators.each( function() {
               ValidatorValidate(this); stepIsValid &= this.isvalid;
            });
            return stepIsValid;
        }
    

提交回复
热议问题