In an C# ASP.NET Web application I am developing, I am making extensive use of nested Web and Custom controls. The Control.FindControl(id) methods is clearly very important in locating subcontrols by id rather than assuming an actual location in the control tree.
However, it appears that it can't always be relied on. Here is a case in point:
In the following control tree fragment:
<table id="ctl00_MstCntPlcHld_VwrPnl_EntityViewer_Ftr_Pgr_ctl00_PgrTbl" cellspacing="0" cellpadding="0" border="0" frame="void" width="790px" style="height:22px">
<tr class="Grid_Footer" style="height:22px">
When executed in the control <span id="ctl00_MstCntPlcHld_VwrPnl_EntityViewer_Ftr_Pgr">, FindControl("PgrTbl") fails to find the enclosed HtmlTable, returning null. Note that no type conversion is performed.
However, the simple following alternative static method does return the correct table:
public static Control FindControlByID(Control parent, String id)
if (parent == null)
foreach (Control control in parent.Controls)
if (control.ID == id)
Control child = FindControlByID(control, id);
if (child != null)
Could anyone tell me whether I have overlooked a feature of FindControl or whether this is a bug?