【发布时间】:2015-03-19 15:07:41
【问题描述】:
我有几个源自BaseCtrl 的用户控件。
BaseCtrl 没有.ascx 标记页面,而只有.cs 文件中的代码定义。
我确信所有明确派生自BaseCtrl 的控件都有一个ChildControl 实例,ID 为CC,在其.ascx 标记页面中定义。
我需要从BaseCtrl 代码中检索派生控件中存在的CC 实例。
Derived1.ascx
...
<uc1:ChildControl runat="server" ID="CC" />
...
Derived1.ascx.cs
public class Derived1 : BaseCtrl { ... }
Derived2.ascx
...
<uc1:ChildControl runat="server" ID="CC" />
...
Derived2.ascx.cs
public class Derived2 : BaseCtrl { ... }
BaseCtrl.cs
public class BaseCtrl : UserControl
{
protected ChildControl DerivedCC
{
get { /* ??? */ }
};
}
如何在BaseCtrl 的DerivedCC 属性中获取派生类的子控件实例?
是否可以在页面生命周期的任何时候获取,或者派生控件是否需要完全加载/初始化?
【问题讨论】:
标签: c# asp.net inheritance webforms user-controls