Is there anyway to find the "main control" on a form and loop through them all, when using master pages, without having to do a massive nested loop such as the following:
//foreach(Control c1 in Page.Controls)
//{
// if(c1.GetType().ToString() == "ASP.site_master")
// {
// foreach(Control c2 in c1.Controls)
// {
// if (c2.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlForm")
// {
// foreach (Control c3 in c2.Controls)
// {
// if (c3.GetType().ToString() == "System.Web.UI.WebControls.ContentPlaceHolder")
// {
// foreach (Control c4 in c3.Controls)
I am trying to do something like the following, using various methods, but all of these have failed. It is more clean and would seem to be more efficient than nested if statements. But these always come back "NULL" everytime. Or do I have to do the nested method. It would seem there should be a way, but I can't find a way.
Control c7 = this.FindControl("ASP.site_master"); Control c5 = Page.FindControl("System.Web.UI.HtmlControls.HtmlForm");
Control c6 = this.FindControl("ContentPlaceHolder1");
Thanks
Andy