You need to use Custom Validator
aspx:
<asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox>
<asp:CustomValidator ID="cvFirstName" runat="server" SetFocusOnError="true" Display="Dynamic"
ValidateEmptyText="true" ControlToValidate="txtFirstName" ClientValidationFunction="validateValue"></asp:CustomValidator>
JS:
<script type="text/javascript">
function validateValue(source, args) {
if (args.Value == "") {
args.IsValid = false;
document.getElementById(source.id.replace('cv', 'txt')).className = 'Invalid';
}
else {
args.IsValid = true;
document.getElementById(source.id.replace('cv', 'txt')).className = 'Valid';
}
}
</script>
CSS:
<style type="text/css">
.Invalid
{
border: 1px solid red;
}
.Valid
{
border: 1px solid White;
}
</style>