Avatar of Arikkan
Arikkan
Flag 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?
JavaScriptC#.NET Programming

Avatar of undefined
Last Comment
Arikkan

8/22/2022 - Mon
Mlanda T

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

ASKER
UI END
<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>  


Backend

            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)

JAVASCRIPT:

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);
    }
}
ASKER CERTIFIED SOLUTION
Jaydev Rathod

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Arikkan

ASKER
Thank you
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck