ForEachControl
Runs action delegate for all controls and subcontrols in ControlCollection.
Source
public static void ForEachControl(this ControlCollection controlCollection, Action<Control> action)
{
if (controlCollection == null)
return;
foreach (Control c in controlCollection)
{
action(c);
if (c.HasControls())
{
ForEachControl(c.Controls, action);
}
}
}
Example
page.Controls.ForEachControl(c =>
{
if (c is HtmlControl)
{
var ctrl = (HtmlControl)c;
if (ctrl.Attributes["class"] != null && ctrl.Attributes["class"] == "hidden")
{
ctrl.Visible = false;
}
}
});