blog.mha.dk
The on-line blog of Michael Holm Andersen

Recursive Page.FindControl

Wednesday, 29 March 2006 15:01 by mha

As far as I know, Microsoft still hasn't added a recursive overload for Page.FindControl - So I guess we still have to make it ourselves:

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

Comments are closed