www.webdeveloper.com
Results 1 to 2 of 2

Thread: CustomValidator client script not firing

  1. #1
    Join Date
    May 2007
    Posts
    5

    CustomValidator client script not firing

    I have a page where the user enters address data. They can select a country from a drop down list. Depending on what country is selected, the user enters their province/state by either a textbox or a drop down list.

    If they select USA/Canada, a drop down list is populated with the states/provinces and made visible, while the state textbox is made invisible. If they select a country other than USA/Canada, the state drop down list is made invisible, and a state textbox is made visible. The first item in the drop down list is "select your state/province" with a value of "".

    I want to use a custom validator to validate the user's state selection. I am working on my javascript validation script, and currently have no server-side validation. The problem is, if the user leaves the state unselected, or changes from a valid state selection to "select your state/province", the validation function never gets called.

    here is my validator:
    Code:
    <asp:CustomValidator ID="cvState" runat="server" ClientValidationFunction="validateStateSelection" ErrorMessage="* Required" ControlToValidate="ddlCountry" ValidateEmptyText="True"></asp:CustomValidator></td>
    here is my validation function:
    Code:
    function validateStateSelection(source, arguments)
    {
        alert("client validation func called");
        alert(arguments.Value);
         	
        if(arguments.Value == null || arguments.Value == "")
        {
            arguments.IsValid = false;
            return;
        }
    	
        arguments.IsValid = true;
    }

  2. #2
    Join Date
    Jan 2003
    Location
    Dundee, Scotland
    Posts
    1,367
    Hi,
    you can have 2 different validation controls to validate the same control.
    You can add a compare validator to the state control. Set your "select your state/province" with a zero or a high number you are sure the rest of the options don't have then set the value to compare to that number. Set the operator to NotEqual.
    ----------------------------------

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles