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 メソッド呼び出しで指定されたコントロールに、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

注釈

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

適用対象