Here is how I handle it. Sometimes depending on how the controls are used or the properties of the control - when in codebehind its difficult to find a control within a control if it hasn't been rendered...Wizard Control for instance - if it contains custom controls you have to do more than the typical find control. This is the code I use for those scenarios:
Place in Base Class...
public Control GetNestedControl(Control skin, string controlID)
{
Control ctlFoundControl = null;
try
{
ctlFoundControl = base.FindControl(controlID);
}
catch(HttpException)
{
ctlFoundControl = null;
}
return (ctlFoundControl != null) ? ctlFoundControl : GetNestedControl(skin.Controls, controlID);
}
public static Control GetNestedControl(ControlCollection col, string id)
{
foreach (Control c in col)
{
Control child = FindNestedControl(c, id);
if(child !=null)
return child;
}
return null;
}
private static Control FindNestedControl(Control root, string id)
{
if (root.ID != null && root.ID == id)
{
return root;
}
foreach (Control child in root.Controls)
{
Control recurse = FindNestedControl(child, id);
if (recurse != null)
{ return recurse; }
}
return null;
}
To use in your control:
On the init or wherever you start the process:
override protected void InitializeSkin(Control skin)
{
Wizard1 = (Wizard)GetControl(skin, "Wizard1"); <--this is the control we can't use the typical FindControl
// the following are in the navigation panes use GetNested instead of GetControl
chkConfirmAction = (CheckBox)GetNestedControl(skin, "chkConfirmAction"); <-
Maybe that will help you in this situation - maybe not :)