I was very excited when writing this general function when the compiler threw an error ( unable to cast T to System.Web.UI.Control)
I basically pass it a type when I call it, and it searches for all the controls for that type. An error occurs whenl.Add((T)ctrl);
private List<T> RecurseTypes<T>(Control ctrls)
{
var l = new List<T>();
foreach (var ctrl in ctrls.Controls)
if (ctrl.GetType() is T)
l.Add((T)ctrl);
return l;
}
Am I missing something or am I just out of luck?
source
share