0

I've got my dynamic validator working, (its creating a span on invalidation client-side), is there a way to control the styling of the invalid input on client-side val? I want to give it a redish background. Looking for a light-weight simplistic solution but open to all options.

Thanks!

1 Answer 1

1

To Exactly quote a previous answer of mine:

This article might help you:

http://msdn.microsoft.com/en-us/library/aa479045.aspx

Particularly this section (look for "Client Side Validation" then under there, "Special Effects"):

<asp:Label id=lblZip runat=server 
   Text="Zip Code:"/> 
<asp:TextBox id=txtZip runat=server 
   OnChange="txtZipOnChange();" /></asp:TextBox><br>
<asp:RegularExpressionValidator id=valZip runat=server
   ControlToValidate=txtZip
   ErrorMessage="Invalid Zip Code" 
   ValidationExpression="[0-9]{5}" /><br>

<script language=javascript>
function txtZipOnChange() {
   // Do nothing if client validation is not active
   if (typeof(Page_Validators) == "undefined")  return;
   // Change the color of the label
   txtZip.style.color = valZip.isvalid ? "Black" : "Red";
}
</script>

There is still some wiring up that needs to be done, which you may be able to tidy up with some jQuery or the like

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.