FindControl<T>
Generic recursive FindControl.
Source
public static T FindControl<T>( this Control startingControl, string id) where T : Control
{
T foundControl = default(T);
int controlCount = startingControl.Controls.Count;
foreach (Control c in startingControl.Controls)
{
if (c is T && string.Equals(id, c.ID,
StringComparison.InvariantCultureIgnoreCase))
{
foundControl = c as T;
break;
}
else
{
foundControl = FindControl<T>(c, id);
if (foundControl != null)
{
break;
}
}
}
return foundControl;
}
Example
Button UpdateButton = Page.FindControl<Button>("UpdateButton");