How to validate ajax cascading dropdown lists RRS feed

  • Question

  • User161915238 posted

    I need to validate ajax cascading dropdown lists. See code below. It does not work. Could anyone help on it. I use VS 2008. Thanks


    <asp:DropDownList ID="ddlTest" runat="server" Width="131px"></asp:DropDownList>


    <asp:RequiredFieldValidator ID="rfvddlTest" runat="server"

    ControlToValidate="ddlTest" ErrorMessage="This field is Required" InitialValue="-1" ValidationGroup="Submit">*</asp:RequiredFieldValidator>


    <cc1:CascadingDropDown ID="cddlTest" runat="server" Category="Test"

                        LoadingText="Loading.." PromptText="-- Select --"   ServiceMethod="GetTestData"

                        ServicePath="~/ddlTestData.asmx" TargetControlID="ddlTest" >


    Wednesday, April 28, 2010 12:30 PM


All replies

  • User-344996941 posted

    Try adding a AppendDataBoundItems="true"  to the cascading dropdownlist and add a list item to be displayed first.

    The below sample code is applied for dropdownlists, see if this works for cascading as well.

    <asp:DropDownList ID="ddlOrderStatus" AppendDataBoundItems="true" runat="server" DataSourceID="odsOrderStatus" >
    <asp:ListItem Text="-Select One--" Value="-1" />


    Friday, April 30, 2010 3:30 AM
  • User161915238 posted

    Hi binoj7

    Thank you for your suggestion. It does not work. The added item does not show in the dropdown list, and the validation does not work.




    Friday, April 30, 2010 8:23 AM
  • User1335925338 posted

    Hi klou,

    Generally, the DropDownList bound with the CascadingDropDown Extender cannot be validated with the RequiredFieldValidator control. That’s because all the DropDownList’s items are generated by the returned value of the CascadingDropDown’s service method and then built as the DOM element of the DropDownList. To achieve this, the page should turn the eventvalidation off.

    So, we cannot set validation on the DropDownList but the generated items inside the WebService. You can add some conditions in the CascadingDropDown extender’s service method to make sure the DropDownLists are built with valid value.

    Other related threads:
    http://forums.asp.net/p/1334592/2695765.aspx#2695765  .

    Best regards,

    Zhi-Qiang Ni

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 5, 2010 3:09 AM
  • User247322785 posted

    klou, I found this solution to validate the cascading dropdown that uses the JQuery get() method. My code resembles yours so I'll include it below in case it is is helpful to others wanting to ensure users make a selection. Note in my example assumes that the first dropdown item is the default "Select a State" that must change to be valid.


    <asp:DropDownList ID="ddlStates" runat="server" Style="width: 227px;" AutoPostBack="false" />
    <cc1:CascadingDropDown runat="server" ID="CascadingDDStates" SelectedValue="00" LoadingText="Loading List of States"
    	ServicePath="StatesService.asmx" ParentControlID="ddlCountry" TargetControlID="ddlStates"
            Category="state" ServiceMethod="GetDropDownContents" EmptyText="No data found"
            EmptyValue="00" />
    <asp:CustomValidator ID="ddStateReq" runat="server" ClientValidationFunction="validateState"
    	ControlToValidate="ddlStates" ErrorMessage="Please select a State" Display="Dynamic" Font-Size="X-Small" Font-Names="Verdana" />
    <script language="javascript" type="text/javascript">
    	function validateState(source, args) {
    	    if ($get("<%=ddlStates.ClientID %>").selectedIndex == 0)
                     args.IsValid = false;
    	    else args.IsValid = true;
                     // some alternate action

    Tuesday, July 30, 2013 1:17 PM
  • User2034544000 posted

    Excelente solución! muchas gracias me ayudo bastante

    Friday, December 13, 2013 1:01 PM
  • Sunday, December 15, 2013 11:03 PM