Рекурсивный поиск контролов в ASP.NET WebForms без рекурсии

01.11.2009 11:26 / Артём Волк / 917 просмотров / ...
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;
}