Get value from cascading dropdown list on postback

Posted on 2009-04-23
Last Modified: 2013-11-08
I am trying to obtain the value of a drop down list populated client side by a cascading drop down and cannot seem to get the selected vaue

I have seen examples where the cascading drop down is added to page_init to let the page know you want to maintain state but this is doing nothing.

I must say that the whole code is inside a user control if it makes any difference

All I want to do is get the selected value from the drop down??

I am using, vs 2008, .Net 3.5 SP1. I am using the ajax toolkit from for the controls and system.web.extensions 3.5
'The button that launces the code, this is in the code behind

Public Sub saveProfilePeriod_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles saveProfilePeriodBtn.Click

        Dim CP As New CarProfile

        CP.ContractPeriodID = makeListExtender.SelectedValue

        CP.Deposit = carDeposit.Text

        CP.Ongoing = carOngoing.Text




    End Sub

This is the update panel with the cascading drop down in where I can not get the posted value

<asp:UpdatePanel ID="newContractPeriodContainer" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">


                    <table class="formTable">


                            <th>Contract Period: </th>

                            <td><div id="contractDropContainer">

                                    <asp:DropDownList ID="ContractPeriodsDrop" runat="server" />

                                    <cc1:CascadingDropDown ID="contractPeriodExtender" runat="server" />


                            <td><a href="javascript: hideContainer('newContractPeriod')">Add new contract period</a></td>


                        <tr id="newContractPeriod" style="display:none">



                                <asp:TextBox ID="contractPerdiodText" runat="server" class="formSmallTextBox" /> months&nbsp;

                                <asp:button CssClass="btnSave" ID="saveContractPeriod" runat="server" OnClick="saveContractPeriod_Click" Text=" " />






                <table class="formTable">


                        <th>Profile: </th>

                        <td><div id="profileDropContainer">

                                <asp:DropDownList ID="profilesList" runat="server">



                                <cc1:CascadingDropDown ID="profileListExtender" ServicePath="~/AdminEventHandlers.asmx" 

                                    ServiceMethod="GetCarProfiles" ParentControlID="ContractPeriodsDrop" TargetControlID="profilesList" PromptText="Select Profile" 

                                    runat="server" Category="Profiles"></cc1:CascadingDropDown>



                        <td><a href="javascript: hideContainer('addProfileContainer')">Add new profile</a></td>


                    <tr id="addProfileContainer" style="display:none">



                            <asp:TextBox ID="carDeposit" runat="server" class="formSmallTextBox" />+

                            <asp:TextBox ID="carOngoing" runat="server" class="formSmallTextBox" />

                            <asp:button CssClass="btnSave" ID="saveProfilePeriodBtn" runat="server" OnClick="saveProfilePeriod_Click" Text=" " />







                        <asp:AsyncPostBackTrigger ControlID="saveContractPeriod" />

                        <asp:AsyncPostBackTrigger ControlID="saveProfilePeriodBtn" />



'This is the page init where the cascading drop down is loaded, this works from a webservice

 Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

            contractPeriodExtender.ServicePath = "~/AdminEventHandlers.asmx"

            contractPeriodExtender.TargetControlID = "ContractPeriodsDrop"

            contractPeriodExtender.PromptText = "Select Contract Period"

            contractPeriodExtender.Category = "ContractPeriods"

            contractPeriodExtender.ServiceMethod = "GetContractPeriods"

    End Sub

Open in new window

Question by:cg_medistox
    LVL 14

    Accepted Solution


    If you are populating any values of Dropdown list in client side, DropDownList1.SelectedIndex or DropDownList1.SelectedValue won't work. Because those are obtained from ViewState. The values added in clientside won't be there in the ViewState.

    Instead you can try this way.

    Instead of DropDownList1.SelectedValue you can the selected value by Request[DropDownList1.UniqueID].
    LVL 10

    Expert Comment

    I get the Values from my Cascading DD's like this:
    Try : If mStateDropDownList.SelectedValue > 0 Then : iState = mStateDropDownList.SelectedValue : Session("StateInt") = iState : End If : Catch : End Try
    BTW, make sure that if you are setting their values on page_load that you do it like this:
    If Not IsPostBack Then
      If Not Session("StateInt") Is Nothing Then  mStateDropDownList_CascadingDropDown.SelectedValue = Session("StateInt")
    End If
    LVL 4

    Author Comment

    I have been looking for that solution for near two days now, my hat goes off to you!

    I cannot find documentation for that anywhere, if there is then its not very well documented

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now