Search code examples
asp.netcustomvalidator

asp.net custom validator not firing.


<script type="text/javascript">
function ValidateProductID(sender, args)
{
    var productID = document.getElementById('<%=txtProductID.ClientID%>').value;
    var productType = document.getElementById('<%=rcbProduct.ClientID%>').value;

    if (productID != "" && productID == "") {
        args.isValid = false;
    }
}

i have this custom validation to validate 2 contorls, ProductType should be selected if productID is entered.

here is the aspx code

 <asp:CustomValidator ID="CustomValidator1" runat="server" EnableClientScript="true" 
                                                       ErrorMessage="please select a Product" 
                                                       ClientValidationFunction="ValidateProductID"
                                                       ControlToValidate ="txtProductID"
                                                       Display = "Dynamic">
                                  </asp:CustomValidator>

the event is not firing, am i missing something ??


Solution

  • if (productID != "" && productID == "")
    

    was wrong (typo) it should be

     if (productID != "" && productType == "")