Dave Burke : Online Community and Social Business Specialist

Referencing a dynamically loaded usercontrol from a child control

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.

 

Comments (0) | Post RSS RSS comment feed

Posted on 4/22/2004 8:48:00 PM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke

Copyright © 2013 Dave Burke.  All Rights reserved.