I have a master page, there’s only one menu item and a contentplaceholder there. I have another web form that inherits form this master page. As nor mal I’ve put all my controls in the contentplaceholder. On my form’s Page_Load event I want to set Enabled=false of all the dropdownlist controls. For this purpose I write:
foreach (Control control in Page.Controls)
{
if (control is DropDownList)
{
DropDownList ddl = (DropDownList)control;
ddl.Enabled = false;
}
}
But all the dropdownlists remain Enabled. When I check for the count of the Page.Control I see only one control and it’s the menuitem of the form’s masterpage. What should I do to get the list of controls that are in my current form?
your foreach loop will not work as your control can have child control and they can also have child control and then DDL.
What I’ll prefer is to create a list of controls first then iterate through that list which is filled with your desire DDL controls.
Later you can directly loop through foundSofar and it is sure that it will contain all DDL controls inside it.