Reminder an micht selbst:
Page.FindControl arbeitet nicht rekursiv. :>
Alternativfunktionen für rekursives Suchen und Holen von Controls:
private T GetControl(string id, ControlCollection ctls, bool ThrowExceptions) where T : Control
{
Control ctl = FindControl(id, ctls);
if (ThrowExceptions && ctl == null)
throw new Exception(string.Format("Cannot find control with id '{0}' !\n", id));
if (ThrowExceptions && ctl.GetType() != typeof(T))
throw new Exception(string.Format("Control with id '{0}' found , but it's type is not {1}!\n", id, typeof(T)));
if (ctl == null) return null;
T castedCtl = (T)ctl;
return castedCtl;
}
private bool ControlExists(string id, ControlCollection ctls)
{
return (GetControl(id, ctls, false)) != null;
}
private Control FindControl(string id, ControlCollection ctls)
{
Control ctlsearched = null;
foreach (Control ctl in ctls)
{
if (!string.IsNullOrEmpty(ctl.ID) && ctl.ID.Equals(id, StringComparison.InvariantCultureIgnoreCase))
ctlsearched = ctl;
if (ctlsearched == null && ctl.HasControls())
ctlsearched = FindControl(id, ctl.Controls);
if (ctlsearched != null) break;
}
return ctlsearched;
}
Update
Manchmal sollte man doch mal Google oder ein paar der Blogs aus seinem RSSReader bemühen… dann wäre man auch auf den Post von Peter Bucher gestossen der das ganze Thema etwas ausführlicher schon im Januar behandelte. :)




Salute
Hier noch ergänzende Möglichkeiten:
- http://www.aspnetzone.de/blogs/peterbucher/archive/2009/01/20/findcontrol-mal-anders-iterativ-rekursiv-generisch-mit-bedingungen.aspx
Gruss Peter
Danke für den Hinweis. ;)