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

サーバー コントロールの親コントロールへの参照。

属性

次の使用例は、ページの新しい Control オブジェクトを、 myControl1メソッド呼び出しで指定されたコントロールに FindControl 設定します。 呼び出しがコントロールを返す場合、コードはプロパティを Parent 使用して、次を含むコントロールを識別します myControl1。 親コントロールが存在する場合は、文字列 "テキスト ボックスの親" が親コントロールのプロパティと ID 連結され、 Page. 親コントロールが見つからない場合は、文字列 "Control not found" が書き込まれます。

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

注釈

ページが要求されるたびに、そのページ上のサーバー コントロールの階層が構築されます。 このプロパティを使用すると、その階層内の現在のサーバー コントロールの親コントロールを特定し、それに対してプログラムを実行できます。

適用対象