开发者

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 contain开发者_如何学Pythoner 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


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");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜