Change Text Box Color using Required Field Validator. No Extender Controls Please

前端 未结 16 2148
广开言路
广开言路 2020-11-28 07:07

I need to change color of TextBox whenever its required field validator is fired on Clicking the Submit button

16条回答
  •  温柔的废话
    2020-11-28 07:43

    Another way,

    $(document).ready(function() {
        HighlightControlToValidate();
        $('#<%=btnSave.ClientID %>').click(function() {
            if (typeof (Page_Validators) != "undefined") {
                for (var i = 0; i < Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid) {
                        $('#' + Page_Validators[i].controltovalidate).css("background", "#f3d74f");
                    }
                    else {
                        $('#' + Page_Validators[i].controltovalidate).css("background", "white");
                    }
                }
            }
        });
    });
    

    Reference: http://www.codedigest.com/Articles/ASPNET/414_Highlight_Input_Controls_when_Validation_fails_in_AspNet_Validator_controls.aspx

提交回复
热议问题