This has been kicking my butt for a while; I've written about it before, and I'm still not happy with the solution. But I'm moving on for now. The problem is how to reference methods and properties in a Parent Usercontrol which is loaded dynamically from another Usercontrol.
I'm using a dynamically loaded Pagetemplate.ascx (from a base page) which loads header and sidebar usercontrols dynamically as well as a “body“ usercontrol, which is determined at runtime by an XML page description lookup file. Referencing this body control has been problematic. Referencing same tier usercontrols is cake, since the comfortable Parent.FindControl() method is available for casting and reference. But referencing the dynamically loaded parent usercontrol, that's a bit more sticky.
Trace is a wonderful thing. A screenshot is below which describes my situation. I'm in the control in red and want to get to the control in blue. Not a clearcut path to follow. Using the .UniqueID property does the job, but I'm not thrilled with it. I played with going down through the tiers starting with the PageMemberTemplate.ascx control [ foreach (Control c in pagememtemplate.Controls) ], looking for the type [ if (c.GetType().ToString() == “ASP._dirbody_ascx“) ] , and if true, grab the UniqueID property for a resulting cast and method call. But my understanding is that the Unique ID of the parent control isn't going to change unless I change the page structure, so going through the tiers finding the runtime UniqueID was an academic exercise only.
But hey, it works.