そのような3つのカスタムユーザーコントロールを定義しました:
public partial abstract class MyAbstractControl : Usercontrol{
// Base class definition here, with common property and methods
public string CommonAttribute {get; set;}
}
public partial class MyConcreteControl1 : MyAbstractControl{
// Some specific stuff here
}
public partial class MyConcreteControl2 : MyAbstractControl{
// Other specific but different stuff here
}
次に、基本クラスのプロパティを持つ別の UserControl を定義しました。
public partial class MyBeautifulControl : UserControl{
[PersistenceMode(PersistenceMode.InnerProperty)]
public MyAbstractControl ChildElement{get;set;}
}
aspx ファイルでは、このコントロールを使用していますが、 MyAbstractControlの代わりにMyConcreteControl1のインスタンスを定義したいと考えています。
しかし、私が書くと:
<MyBeautifulControl runat="server" id="beautiful">
<ChildElement commonAttribute="value" />
</MyBeautifulControl>
ChildElementはMyAbstractControlインスタンスとしてのみ定義できます。コンテキストに応じてMyConcreteControl1またはMyConcreteControl2インスタンスを作成したいのですが、方法がわかりません。