Control.Parent 속성

정의

페이지 컨트롤 계층 구조에서 서버 컨트롤의 부모 컨트롤에 대한 참조를 가져옵니다.

public:
 virtual property System::Web::UI::Control ^ Parent { System::Web::UI::Control ^ get(); };
[System.ComponentModel.Browsable(false)]
public virtual System.Web.UI.Control Parent { get; }
[System.ComponentModel.Browsable(false)]
[System.ComponentModel.Bindable(false)]
public virtual System.Web.UI.Control Parent { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Parent : System.Web.UI.Control
[<System.ComponentModel.Browsable(false)>]
[<System.ComponentModel.Bindable(false)>]
member this.Parent : System.Web.UI.Control
Public Overridable ReadOnly Property Parent As Control

속성 값

Control

서버 컨트롤의 부모 컨트롤에 대한 참조입니다.

특성

예제

다음은 페이지의 myControl1Control 개체를 메서드 호출에 지정된 컨트롤로 설정하는 예제입니다FindControl. 호출에서 컨트롤을 반환하는 경우 코드는 Parent 속성을 사용하여 포함하는 컨트롤을 식별합니다 myControl1. 부모 컨트롤이 있는 경우 문자열 "텍스트 상자의 부모입니다"는 부모 컨트롤의 속성과 ID 연결되고 Page. 부모 컨트롤이 없으면 "컨트롤을 찾을 수 없음" 문자열이 작성됩니다.

private void Button1_Click(object sender, EventArgs MyEventArgs)
{
      // Find control on page.
      Control myControl1 = FindControl("TextBox2");
      if(myControl1!=null)
      {
         // Get control's parent.
         Control myControl2 = myControl1.Parent;
         Response.Write("Parent of the text box is : " + myControl2.ID);
      }
      else
      {
         Response.Write("Control not found");
      }
}

Private Sub Button1_Click(sender As Object, MyEventArgs As EventArgs)
' Find control on page.
Dim myControl1 As Control = FindControl("TextBox2")
If (Not myControl1 Is Nothing)
   ' Get control's parent.
   Dim myControl2 As Control = myControl1.Parent
   Response.Write("Parent of the text box is : " & myControl2.ID)
Else
   Response.Write("Control not found.....")
End If
End Sub

설명

페이지가 요청되면 해당 페이지의 서버 컨트롤 계층 구조가 빌드됩니다. 이 속성을 사용하면 해당 계층에서 현재 서버 컨트롤의 부모 컨트롤을 확인하고 이에 대해 프로그래밍할 수 있습니다.

적용 대상