1

Is it possible to add css class to validated input if value isnt valid ? Im using asp.net validators.

Maybe there is javascript event on taht validators which I can use ?

thanks for any advice

gruber
  • 28,739
  • 35
  • 124
  • 216

4 Answers4

1

It is hard to do that with normal ASP.NET Validators as it don't provide a rich client-side library.

If you don't need to change your current validators types. you can use the HighlightCssClass property of ValidatorCallout control from ASP.NET Ajax Toolkit.

You can check a demo here:

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ValidatorCallout/ValidatorCallout.aspx

Mohamed Ramadan
  • 793
  • 5
  • 15
0

You could use the build-in CustomValidator like so:

<asp:CustomValidator ID="vldCustomValidator" EnableClientScript="true"
    ErrorMessage="Your error message goes here"
    ClientValidationFunction="JavascriptValidationFunction" 
    ControlToValidate="txbControl"
    runat="server" />

Usage scenario: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.customvalidator.clientvalidationfunction.aspx

MonkeyCoder
  • 2,600
  • 2
  • 28
  • 30
0

You could override the Default ASP.NET validation script and inject your own script to add the classes to parent div.

More info here: https://stackoverflow.com/a/9857696/618044

Community
  • 1
  • 1
Jeremy A. West
  • 2,162
  • 4
  • 27
  • 40
-1

you can do it in this way. you add custom HTML tags and CSS class.

<asp:RequiredFieldValidator ID="RrequiredFieldValidator1" runat="server"
    ControlToValidate="txtCustomerName" ForeColor="Red"
    Display="Dynamic">
    <span class="bubbletooltip">Please Enter Name Here</span>
   </asp:RequiredFieldValidator>
Ashfaq Shaikh
  • 1,648
  • 12
  • 20