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

前端 未结 16 2176
广开言路
广开言路 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

    I liked Alexander's answer, but wanted the javascript to be more generic. So, here is a generic way of consuming the errors from a custom validator.

        function ValidateTextBox(source, args) {
            var cntrl_id = $(source).attr("controltovalidate");
            var cntrl = $("#" + cntrl_id);
            var is_valid = $(cntrl).val() != "";
            is_valid ? $(cntrl).removeClass("error") : $(cntrl).addClass("error");
    
            args.IsValid = is_valid;
        }
    

提交回复
热议问题