2009-06-25 1 views
0

私は柔軟なCompositeControlを構築しようとしています。いくつかのパラメータによっては、CompositeControlがCreateChildControlsメソッドで異なるユーザーコントロールをロードするようにしたいと思います。正確なUserControlsは設計時にはわかりません。 CompositeコントロールにUserControlを追加することはできますか?

はちょうど簡単な例として、私は「ハードコーディングされた」ユーザーコントロールを試み、それが失敗しました:

protected override void CreateChildControls() 
    {    
     Control UserControlControl = Page.LoadControl(typeof(MyUserControl), null); 
     Controls.Add(UserControlControl); 
     Label RegularControl = new Label(); 
     RegularControl.Text = "This gets displayed"; 
     Controls.Add(RegularControl); 
    } 

それは私が探しているものを達成することは可能ですか?

おかげ

+0

何? – womp

答えて

2

は、以下のことを試してみてください。エラーメッセージだった

protected override void CreateChildControls() 
{    
      Control UserControlControl = Page.LoadControl("~/path/to/control.ascx"); 
      Controls.Add(UserControlControl); 
} 
+0

うん、それはそれをした。これは行いますが、私は引き続き引数として型を持つ他のオーバーロードメソッドを使用する方法を学ぶことに興味があります。 –

関連する問題