I have been pondering how I can get all controls on a page and then perform a task on them in this related question:
How to Search Through a C# DropDownList Programm
Here is a recursive version that returns a control collection of the requested type instead of utilizing another argument:
using System.Collections.Generic;
using System.Web.UI;
// ...
public static List GetControls(ControlCollection Controls)
where T : Control {
List results = new List();
foreach (Control c in Controls) {
if (c is T) results.Add((T)c);
if (c.HasControls()) results.AddRange(GetControls(c.Controls));
}
return results;
}
Insert into your class (static optional).