EmptyControlCollection コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > EmptyControlCollection コンストラクタの意味・解説 

EmptyControlCollection コンストラクタ

EmptyControlCollection クラス新しインスタンス初期化します。

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Dim owner As Control

Dim instance As New EmptyControlCollection(owner)
public EmptyControlCollection (
    Control owner
)
public:
EmptyControlCollection (
    Control^ owner
)
public EmptyControlCollection (
    Control owner
)
public function EmptyControlCollection (
    owner : Control
)

パラメータ

owner

このコレクションを子コントロールコレクションとして所有している Control

使用例使用例

コントロールを持つコントロール設定しようとして例外発生するコード例次に示します。この例外は、コンテナ コントロールで子コントロール許可されていないために発生します実行可能ファイル作成するために使用されるコマンド ライン次に示します

vbc /r:System.dll /r:System.Web.dll /t:library
       /out:myWebAppPath/bin/vb_myEmptyControlCollection.dll
       myEmptyControlCollection.vb
csc /t:library /out:myWebAppPath/bin/cs_myEmptyControlCollection.dll
    myEmptyControlCollection.cs
' File name: emptyControlCollection.vb.

Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections


Namespace CustomControls 

  Public Class MyVB_EmptyControl 
    Inherits Control
    
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _
    Protected Overrides Function
 CreateControlCollection() As ControlCollection
    ' Function Name: CreateControlCollection.
    ' Denies the creation of any child control by creating an empty
 collection.
    ' Generates an exception if an attempt to create a child control
 is made.
      Return New EmptyControlCollection(Me)
    End Function 
    
    <System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand,
 Name:="FullTrust")> _  
    Protected Overrides Sub
 CreateChildControls()
    ' Sub Name: CreateChildControls.
    ' Populates the child control collection (Controls). 
    ' Note: This function will cause an exception because the control
 does not allow 
    ' child controls.
      Dim text As LiteralControl
      text = New LiteralControl("<h5>Composite
 Controls</h5>")
      Controls.Add(text)
    End Sub 
  End Class 

End Namespace 

/* File name: emptyControlCollection.cs. */

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

namespace CustomControls
{

  // Defines a simple custom control.
  public class MyCS_EmptyControl : Control
  {
    [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name="FullTrust")] 
    protected override ControlCollection CreateControlCollection()
 
    /*
     * Function Name: CreateControlCollection.
     * Denies the creation of any child control by creating an empty collection.
     * Generates an exception if an attempt to create a child
 control is made.
     */
     {
       return new EmptyControlCollection(this);
     }
     
     [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand,
 Name="FullTrust")] 
     protected override void CreateChildControls()
     /*
      * Function Name: CreateChildControls.
      * Populates the child control collection (Controls). 
      * Note: This function will cause an exception because the control does not
 allow 
      * child controls.
      */
      {
        // Create a literal control to contain the header and add it
 to the collection.
        LiteralControl text;
        text = new LiteralControl("<h5>Composite Controls</h5>");
        Controls.Add(text);
      }
   }

}
/* File name: emptyControlCollection.jsl. */
import System.*;
import System.Web.*;
import System.Web.UI.*;
import System.Web.UI.WebControls.*;
import System.Collections.*;

// Defines a simple custom control.
public class MyJSL_EmptyControl extends Control
{
//    /** @attribute System.Security.Permissions.PermissionSet(
//        System.Security.Permissions.SecurityAction.Demand, Name =
 "FullTrust")
//     */
    protected ControlCollection CreateControlCollection()
    /*
        Function Name: CreateControlCollection.
        Denies the creation of any child control by creating an empty
        collection.
        Generates an exception if an attempt to create a child
 control is
        made.
    */
    {        
        return new EmptyControlCollection(this);
    } //CreateControlCollection

    /** @attribute System.Security.Permissions.PermissionSet(
        System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")
     */
    protected void CreateChildControls()
    /*
        Function Name: CreateChildControls.
        Populates the child control collection (Controls). 
        Note: This function will cause an exception because the control
        does not allow child controls.
     */
    {        
        // Create a literal control to contain the header and add it
 to the
        // collection.
        LiteralControl text;
        text = new LiteralControl("<h5>Composite Controls</h5>");
        get_Controls().Add(text);
    } //CreateChildControls
} //MyJSL_EmptyControl

上記定義した空のカスタム コントロール使用するコード例次に示します。この例を実行すると、例外発生しますRegister ディレクティブ示される値には、前のコマンド ライン反映されます。

<%@ Register TagPrefix="custom" Assembly="vb_myEmptyControlCollection"
 Namespace="CustomControls" %>
 <html>
  <body>
  <h1>Using an Empty Control</h1>
  <custom:MyVB_EmptyControl id="vbEmptyControlId"
 runat="server"/>
  </body>
 </html>
<%@ Register TagPrefix="custom" Assembly="cs_myEmptyControlCollection"
 Namespace="CustomControls" %>
 <html>
  <body>
  <h1>Using an Empty Control </h1>
  <custom:MyCS_EmptyControl id="csEmptyControlId" runat="server"/>
  </body>
 </html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
EmptyControlCollection クラス
EmptyControlCollection メンバ
System.Web.UI 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「EmptyControlCollection コンストラクタ」の関連用語

EmptyControlCollection コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



EmptyControlCollection コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS