Recursive version of the FindControl(..) method
1 min read
1 min read
/// <summary>
/// Recursive version of the FindControl method.
/// </summary>
/// <param name="parent">Parent to where to start the search for the control</param>
/// <param name="controlId">ID of the control to search for</param>
/// <returns></returns>
public static Control FindControlRecursive(Control parent, string controlId)
{
if (controlId == parent.ID)
return parent;
foreach (Control ctrl in parent.Controls)
{
Control tmp = FindControlRecursive(ctrl, controlId);
if (tmp != null)
return tmp;
}
return null;
}