Asp.net has a javascript client function for managing validators, the "ValidatorEnable" function,
ValidatorEnable(RequiredFieldValidatorId, false);
You can call it simply using javascript, you must send the validator object to the function (and not just its identifier).
if (x==y) { ValidatorEnable($('#<%=rfvFamily.ClientID %>'), false); } else { ValidatorEnable($('#<%=rfvFamily.ClientID %>'), true); }
or
if (x==y) { ValidatorEnable(document.getElementById("<%=rfvFamily.ClientID %>", false); } else { ValidatorEnable(document.getElementById("<%=rfvFamily.ClientID %>", true); }
full documentation at: http://msdn.microsoft.com/en-us/library/Aa479045#aspplusvalid_clientside
Another way is to set CausesValidation = "false" in your DropDownList so that the validators do not block the postback when the DropDownList record is changed.
(*) Remember that this function is intended for the client side, to disable the server-side validator, you must also disable the validator when posting the page back.
if (IsPostBack){ if (x==y) { rfvFamily.Enabled = false; } }
Zakaria habibi
source share