Рекурсивный поиск контролов в ASP.NET WebForms без рекурсии
public static Control FindControlRecursively(Control root, string id)
{
Stack<Control> stack = new Stack<Control>();
stack.Push(root);
while (stack.Count > 0)
{
Control current = stack.Pop();
if (current.ID == id)
{
return current;
}
foreach (Control control in current.Controls)
{
stack.Push(control);
}
}
return null;
}
