ValidatorEnable not working

Arikkan used Ask the Experts™
I am trying to use the ValidatorEnable() on a page.
As I debug, the code calls the Javascript with the Validators. I can even see that the Validators get enabled after the javascript function runs.

But then no validation message shows on the page for the validations.
If I enable the same Validators thru backend code, they work as needed. But I need to do this on the page when controls are changed, so I need client side ValidatorEnable().

What am I missing?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
It might help if you posted a sample of what your validator code looks like. I take it you are using CustomValidators. Are you setting args.IsValid? Do you have a ValidationSummary on the page? Are you using ValidationGroups? What happens if you try to manually call Page_ClientValidate() on the client side (or Page_ClientValidate('groupname') is using ValidationGroups)?


<asp:TextBox ID="txtStreetName" runat="server" CssClass="Size" MaxLength="50"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvStreetName" runat="server"                                     ControlToValidate="txtStreetName" Display="None" ErrorMessage="Street cannot be null"
ValidationGroup = "AddressInformation"></asp:RequiredFieldValidator>  


            Dim residentialAddressValidatorsCheck As String = "ResidentialAddressValidatorsCheck('"
                                                                                                         Me.rfvHouse.ClientID() & "','" & _
                                                                                                         Me.rfvStreetName.ClientID() & "','" & _
                                                                                                         Me.rfvAddress.ClientID() & "','" & _
                                                                                                         Me.rfvtxtResidentialCity.ClientID() & "','" & _
                                                                                                         Me.rfvCity.ClientID() & "','" & _
                                                                                                         Me.ddlState.ClientID & "','" & _
                                                                                                         Me.rfvZipCode1.ClientID & "','" & _
                                                                                                         Me.rfvResZipCode5Digits.ClientID() & _

                  ChkAgree.Attributes.Add("onclick", residentialAddressValidatorsCheck)
                  ScriptManager.RegisterStartupScript(Page, Page.GetType(), "HideAddress", residentialAddressValidatorsCheck, True)


function ResidentialAddressValidatorsCheck(objrfvHouse, objrfvStreetName, objrfvAddress, objrfvtxtResidentialCity, objrfvCity, objddlState, objrfvZipCode1, objrfvResZipCode5Digits)
    var rfvHouse = document.getElementById(objrfvHouse);
    var rfvStreetName = document.getElementById(objrfvStreetName);
    var rfvAddress = document.getElementById(objrfvAddress);
    var rfvtxtResidentialCity = document.getElementById(objrfvtxtResidentialCity);
    var rfvCity = document.getElementById(objrfvCity);
    var ddlState = document.getElementById(objddlState);
    var rfvZipCode1 = document.getElementById(objrfvZipCode1);
    var rfvResZipCode5Digits = document.getElementById(objrfvResZipCode5Digits);

    if (someCondition == "True")
                ValidatorEnable(rfvHouse, false);
                ValidatorEnable(rfvStreetName, false);
                ValidatorEnable(rfvAddress, true);
                ValidatorEnable(rfvtxtResidentialCity, true);
                ValidatorEnable(rfvCity, false);
                ValidatorEnable(rfvZipCode1, true);
                ValidatorEnable(rfvResZipCode5Digits, true);
Sr. Software Engineer
 Call below function on button OnClientClick event or call when you want to check your validation.



Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial