Reputation: 3
I Have a panel that is disabled. And hence all the controls inside the panel are disabled. On Postback I need to enable only one control which is inside a disabled panel. Please let me know how we can achieve this. Below is the Code
<asp:Panel ID="testPanel" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:DropDownList ID="dropdownlist" runat="server"></asp:DropDownList>
</asp:Panel>
Codebehind aspx.cs
testpanel.Enabled = false;
dropdownlist.Enavbled=true;
Here the dropdownlist is not getting enabled. Please let me know a way to enable it. Iterating through panel is a performance as I have many controls inside it. So I need a better way to enable the DropDownList inside a Disabled Panel.
Upvotes: 0
Views: 1614
Reputation: 460098
You cannot enable a single control in a container control that is disabled because that property is inherited (in the same manner as Visible
). So the only way is to enable the Panel
and this control but disable all other controls in the panel.
dropdownlist.Enabled = true;
testpanel.Enabled = dropdownlist.Enabled;
// disable all other controls in the panel
TextBox1.Enabled = false;
MSDN:
This property propagates down the control hierarchy. If you disable a container control, the child controls within that container are also disabled. For more information, see the
IsEnabled
property.
Upvotes: 1