If you want to handle it on the client side, let's say you have a required field validator set up like this:
<asp:TextBox ID="txtName" runat="server" ClientIDMode="Static"></asp:TextBox>
<asp:RequiredFieldValidator ID="reqValName" ControlToValidate="txtName" runat="server"
CssClass="validation" ErrorMessage="*Required">
</asp:RequiredFieldValidator>
ASP.NET 4.0 will generate JavaScript code for you as shown below:
var reqValName = document.all ? document.all["reqValName"] : document.getElementById("reqValName");
reqValName.controltovalidate = "txtName";
reqValName.errormessage = "*Required";
reqValName.enabled = "False"; // <---- THIS LINE DISABLES THE VALIDATOR ON SERVER SIDE.
reqValName.evaluationfunction = "RequiredFieldValidatorEvaluateIsValid";
reqValName.initialvalue = "";
The line reqValName.enabled = "False";
is only generated when the validator is disabled, so you can use that information to determine its state. Remember that the value of enabled is a string and consider placing your checking JavaScript at the bottom of the page (before closing body tag).
In ASP.NET 4.5, things are easier to check since the attribute is now in the data-val-enabled
attribute of the span
element rather than a JavaScript variable. Take a look at the HTML generated by ASP.NET 4.5:
<span class="validation" id="reqValName" style="visibility: hidden;" data-val-initialvalue=""
data-val-evaluationfunction="RequiredFieldValidatorEvaluateIsValid" data-val="true" data-val-enabled="False"
data-val-errormessage="*Required" data-val-controltovalidate="txtName">