다음을 통해 공유


Control.CreateChildControls 메서드

정의

다시 게시 또는 렌더링하기 위한 준비 작업으로, 포함된 자식 컨트롤을 만들도록 컴퍼지션 기반 구현을 사용하는 서버 컨트롤에 알리기 위해 ASP.NET 페이지 프레임워크에 의해 호출됩니다.

protected:
 virtual void CreateChildControls();
protected public:
 virtual void CreateChildControls();
protected virtual void CreateChildControls ();
protected internal virtual void CreateChildControls ();
abstract member CreateChildControls : unit -> unit
override this.CreateChildControls : unit -> unit
Protected Overridable Sub CreateChildControls ()
Protected Friend Overridable Sub CreateChildControls ()

예제

다음 예제에서는 재정의된 버전의 메서드를 보여 줍니다 CreateChildControls . 이 구현에서 복합 컨트롤은 HTML을 렌더링하는 TextBox 두 개의 리터럴 컨트롤로 묶인 컨트롤을 표시합니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

// Override CreateChildControls to create the control tree.
 [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="Execution")]
 protected override void CreateChildControls() {

     // Add a LiteralControl to the current ControlCollection.
     this.Controls.Add(new LiteralControl("<h3>Value: "));

     // Create a text box control, set the default Text property, 
     // and add it to the ControlCollection.
     TextBox box = new TextBox();
     box.Text = "0";
     this.Controls.Add(box);

     this.Controls.Add(new LiteralControl("</h3>"));
 }

' Override CreateChildControls to create the control tree.
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="Execution")> _
Protected Overrides Sub CreateChildControls()
   
   ' Add a LiteralControl to the current ControlCollection.
   Me.Controls.Add(New LiteralControl("<h3>Value: "))
   
   
   ' Create a text box control, set the default Text property, 
   ' and add it to the ControlCollection.
   Dim box As New TextBox()
   box.Text = "0"
   Me.Controls.Add(box)
   
   Me.Controls.Add(New LiteralControl("</h3>"))
End Sub

설명

복합 또는 템플릿 서버 컨트롤을 개발하는 경우 이 메서드를 재정의해야 합니다. 메서드를 재정의하는 컨트롤은 CreateChildControls 명명 충돌을 방지하기 위해 인터페이스를 구현 INamingContainer 해야 합니다.

자세한 내용은 웹 서버 컨트롤 템플릿사용자 지정 ASP.NET 서버 컨트롤 개발을 참조하세요.

적용 대상

추가 정보