When iterating through a collection of all controls on a page (from Page.Controls and those control’s children and their children’s children etc), how can you tell if the control came from the Page’s Master Page?
The following seems to work, but feels a bit dirty. Is there a better way to get this information?
Update: Sorry, missed some code out earlier.
List<Control> allControls = GetAllControls(this.Page)
foreach (Control c in allControls)
{
bool isFromMaster = c.NamingContainer.TemplateControl.GetType().BaseType.BaseType == typeof(MasterPage);
}
Where GetAllControls recursively gets all controls on a page
Thanks
Solution turned out to be going through the controls from the master page, excluding the children of content place holders (as these give you the controls added from the page itself).