Link to home
Create AccountLog in
Avatar of patd1
patd1Flag for United States of America

asked on

enable/disable a drop down list based on selection of another drop down list

I am using .net 3.5 with C#. I have three drop down lists in a panel. I want to disable the second and the third drop down until a selection is made on the first. I tried the following:
disable second and third drop down lists on Page_Load. Then enable both of them in the OnSelectedIndexChanged event for the first drop down, but it does not enable them, probably because it is a client side event.

How can I accomplish this?

Thanks.
Avatar of static-void
static-void

Is this winforms or webforms?
Avatar of patd1

ASKER

static-void:
Is this winforms or webforms?

This is webforms.
Avatar of patd1

ASKER

if I split them into two panels where panel 1 has first drop down list and panel2 ahs the the other 2 drop down lists, ho do I disable panel 2 until a selection has been made on panel 1?
Ok make sure your disabling code on page load is inside a if(!IsPostback){ } statement
Avatar of patd1

ASKER

Here's what I am doing and the process works, but it refreshes the whole page when I change the selection in my first drop down list (ddl), to enable the other two ddl s.
How can I make it refresh "panel3 only" when  selectedIndex gets changed on the first ddl.
I tried using AJAX update panel, but it starts giving me error when I add this line of code:
<%@ Register Assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxtoolkit" %> and <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

Error:Microsoft JScript runtime error: Sys.ArgumentTypeException: Object of type 'Object' cannot be converted to type 'Array'.
Parameter name: array
<asp:Panel ID="panel2" runat="server" GroupingText="CLIENT" EnableViewState="true" >
                    <table >
                        <tr>
                         <td class="cls">CLIENT</td><td><asp:DropDownList ID="adv_client" runat="server" OnSelectedIndexChanged="adv_client_SelectedIndexChanged" 
                             OnInit="adv_client_Init" AutoPostBack="true"></asp:DropDownList></td>
                        </tr>
                        </asp:Panel>
                    </table> 
                    <asp:Panel ID="panel3" runat="server" GroupingText="Facilities" EnableViewState="true" >
                    <table> 
                        <tr>
                            <td class="cls">Facility1</td><td><asp:DropDownList ID="adv_ord_ddl" runat="server" 
                                onselectedindexchanged="adv_ord_ddl_SelectedIndexChanged" 
                                 oninit="adv_ord_ddl_Init" ></asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <td class="cls">Department</td><td><asp:DropDownList ID="adv_treat_ddl" runat="server" OnSelectedIndexChanged="adv_treat_ddl_SelectedIndexChanged"
                             OnInit="adv_treat_ddl_Init"></asp:DropDownList></td>
                        </tr>
                        </asp:Panel>
                    </table> 

 protected void Page_Load(object sender, EventArgs e)
    {.....

if (!IsPostBack)
        {
            this.panel3.Enabled = false;
...
}
}
protected void adv_client_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["adv_client"] = adv_client.SelectedItem.Value;
        if (adv_client.SelectedIndex > 0)
        {
            this.panel3.Enabled = true;
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of patd1
patd1
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of patd1

ASKER

it works