Link to home
Start Free TrialLog in
Avatar of Arikkan
ArikkanFlag for United States of America

asked on

ValidatorEnable not working

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?
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

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)?
Avatar of Arikkan


<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);
Avatar of Jaydev Rathod
Jaydev Rathod

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Arikkan


Thank you