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

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

    I had to make a few changes to Steve's suggestion to get mine working,

     function ValidateTextBox(source, args) {
        var controlId = document.getElementById(source.controltovalidate).id;
        var control = $("#" + controlId);
        var value = control.val();
        var is_valid = value != "";
        is_valid ? control.removeClass("error") : control.addClass("error");
        args.IsValid = is_valid;
      }
    

    great example though, exactly what I needed.

提交回复
热议问题