Now I know this does not make for good design practice, however it is legacy code with a bug that needs fixing so I am going to have to live with it.
The scenario is I have a set of nest Master pages (3 deep), call them Base > Template > 2Col. I am working at the 2Col level. As the name suggests the 2Col master page has two content placeholders, MainContent and SideContent.
I have user UserControl in MainContent that needs to reference another UserControl in SideContent.
ContentPlaceHolder ph = (ContentPlaceHolder)this.Page.Master.FindControl("SideContent");
MyUserControl uc = (MyUserControl )ph.FindControl("MyUserControl1");
I am not sure why this doesn’t work, the intellisense when I debug would lead me to think that the ContentPlaceHolder is there, but the first line always returns null?
Thanks in advance!
Because of the nesting of Master pages you need access the correct master page like so:
Alternatively if you need to find any control on the Page from the Master use the following: