Q:

Storing a reference to the Parent control in Session

I have an ASP.NET web form that has a "container" usercontrol that hosts several custom user controls on the page.  The controls can be hosted directly in the container or can be children of other usercontrols.  The container usercontrol has several public properties exposed that I sometimes need to get to from within the child user controls.  I've been using some form of "this.Parent" or "this.Parent.Parent" to get back to the base control.
What would be the impact of storing a reference to "this" into Session from the base control so I can access it from within the event handlers within the user controls?
Thanks,
Darvis

A:

You can put this in your page:
public MyControlType MyParentControl
{
   get
   {
       return this._myParentUserControl;
   }
}

And put this in your Custom Controls:
var parentPage = this.Page as MyBasePageType;
if(parentPage !=null){
    parentPage.MyParentControl.WhateverFuncNameYouNeed("myParams");
}

