Wednesday, September 17, 2008

Recursive FindControl

The following method can be used to find a control recursively:

private Control FindControlRecursive(Control root, string id) 
{
if (root.ID == id)
{
return root;
}

foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}

return null;
}