Recursive Page.FindControl for C#

This makes life much easier when you are trying to get to controls that are themselves contained within other containers, for example a TextBox inside a DataView or DataList.

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;
}