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!

Recommended Answers

Do your code behind functions fire on postback?

Jump to Post

All 4 Replies

Do your code behind functions fire on postback?

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?

Be sure to register both dropdowns in the scriptmanager.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.