Hi guys,

I've been trying to update an updatepanel with the selected values of two dropdownlists. The updatepanel is supposed to be updated on selectedindex changed of the second dropdown. The update works on the first initial index changed, but does not work for any subsequent index change.

The markup is as such:

<asp:UpdatePanel runat="server" ID="pnl1" UpdateMode="Always">
        <div id="blah" runat="server" class="well well-large" style="height:100px;">
        <asp:DropDownList ID="ddl1" runat="server" OnSelectedIndexChanged="func1_click" AutoPostBack="true" /><br />
        <asp:DropDownList ID="ddl2" runat="server" OnSelectedIndexChanged="func2_click" AutoPostBack="true"  />

<asp:UpdatePanel runat="server" ID="pnl2" UpdateMode="Always">
            <asp:AsyncPostBackTrigger ControlID="ddl2" EventName="SelectedIndexChanged" />
            <asp:Label ID="lbl" runat="server" />

The Codebehind functions:

protected void func1_click(object sender, EventArgs e)
    if (ddl1.SelectedValue == "")
        ddl2.Visible = false;
        SqlCommand cmd = new SqlCommand("SELECT blah blah...", con);
        cmd.Parameters.AddWithValue("@id", ddl1.SelectedValue);

        ddl2.DataSource = cmd.ExecuteReader();
        ddl2.DataTextField = "text";
        ddl2.DataValueField = "value";
        ddl2.Items.Insert(0, new ListItem("--Select--", ""));
        ddl2.SelectedIndex = 0;
        ddl2.Visible = true;

protected void func2_click(object sender, EventArgs e)
    lbl.Text = ddl1.SelectedItem + " > " + ddl2.SelectedItem;

When I try to toggle the the second dropdownlist more than once, it does not update the update panel. I have to toggle the first dropdownlist and then the second dropdownlist to see results. If this is not clear, please let me know. Thanks for your help!

Edited by while(!success)

4 Years
Discussion Span
Last Post by ggamble

func1 always fires, func2 fires on the first indexchange, but not subsequent index changes


Upon further investigation, ddl2 always defaults to the value of the first index. Postback issue?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.