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
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
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
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
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>