TemplateControl.LoadControl メソッド (Type, Object[])
アセンブリ: System.Web (system.web.dll 内)

Dim instance As TemplateControl Dim t As Type Dim parameters As Object() Dim returnValue As Control returnValue = instance.LoadControl(t, parameters)
- t
コントロールの型。
- parameters
呼び出すコンストラクタのパラメータと、数、順序、および型が一致する引数の配列。parameters が空の配列または null 参照 (Visual Basic では Nothing) である場合は、パラメータをとらないコンストラクタ (既定のコンストラクタ) が呼び出されます。
指定された UserControl を返します。

コントロールがキャッシュをサポートする場合、LoadControl メソッドから返されるオブジェクトは、実際には、UserControl オブジェクトではなく PartialCachingControl オブジェクトになります。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


TemplateControl.LoadControl メソッド

名前 | 説明 |
---|---|
TemplateControl.LoadControl (String) | 指定された仮想パスに基づいてファイルから Control オブジェクトを読み込みます。 |
TemplateControl.LoadControl (Type, Object[]) | 指定された型とコンストラクタ パラメータに基づいて Control オブジェクトを読み込みます。 |

TemplateControl.LoadControl メソッド (String)
アセンブリ: System.Web (system.web.dll 内)

Dim instance As TemplateControl Dim virtualPath As String Dim returnValue As Control returnValue = instance.LoadControl(virtualPath)
戻り値
指定された Control を返します。


コントロールがキャッシュをサポートする場合、LoadControl メソッドから返されるオブジェクトは、実際には、Control オブジェクトではなく PartialCachingControl オブジェクトになります。virtualPath パラメータが相対パスの場合、読み込まれるコントロールのパスは TemplateControl のパスに対しての相対になります。

LoadControl メソッドを使用して、ASP.NET ページにユーザー コントロールを追加する方法を次のコード例に示します。ユーザー コントロールは次のファイルに格納されています。
[C#]
TempControl_Samples1.cs.ascx
TempControl_Samples1.vb.ascx
その後、このユーザー コントロールは Placeholder1 という名前の PlaceHolder Web サーバー コントロールの Controls プロパティに追加されます。
このコード例で使用されている MyControl クラスの定義については、「TemplateControl」を参照してください。
' When this page is loaded, it uses the TemplateControl.LoadControl ' method to programmatically create a user control. The user control ' is contained in the .ascx file that is passed as a parameter ' in the LoadControl call. The page then adds the control to its ' ControlCollection. Sub Page_Load(Sender As Object, e As EventArgs) ' Obtain a UserControl object MyControl from the ' user control file TempControl_Samples1.vb.ascx. Dim myControl1 As MyControl = CType(LoadControl("TempControl_Samples1.vb.ascx") ,MyControl) PlaceHolder1.Controls.Add(myControl1) End Sub
// When this page is loaded, it uses the TemplateControl.LoadControl // method to programmatically create a user control. The user control // is contained in the .ascx file that is passed as a parameter // in the LoadControl call. The page then adds the control to its // ControlCollection. void Page_Load(object sender, System.EventArgs e) { // Obtain the UserControl object MyControl from the // user control file UserControl_Init.ascx. MyControl myControl1 = (MyControl)LoadControl("TempControl_Samples1.cs.ascx"); PlaceHolder1.Controls.Add(myControl1); }

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TemplateControl.LoadControl メソッドのページへのリンク