.NET Framework Class Library
Control..::.Parent Property

Updated: November 2007

Gets a reference to the server control's parent control in the page control hierarchy.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

Visual Basic (Declaration)
<BindableAttribute(False)> _
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property Parent As Control
Visual Basic (Usage)
Dim instance As Control
Dim value As Control

value = instance.Parent
C#
[BindableAttribute(false)]
[BrowsableAttribute(false)]
public virtual Control Parent { get; }
Visual C++
[BindableAttribute(false)]
[BrowsableAttribute(false)]
public:
virtual property Control^ Parent {
    Control^ get ();
}
J#
/** @property */
/** @attribute BindableAttribute(false) */
/** @attribute BrowsableAttribute(false) */
public Control get_Parent()
JScript
public function get Parent () : Control

Property Value

Type: System.Web.UI..::.Control

A reference to the server control's parent control.

Whenever a page is requested, a hierarchy of server controls on that page is built. This property allows you to determine the parent control of the current server control in that hierarchy, and to program against it.

The following example sets a new Control object on a page, myControl1, to the control specified in a FindControl method call. If the call returns a control, the code uses the Parent property to identify the control that contains myControl1. If the parent control exists, the string "The parent of the text box is" is concatenated with the ID property of the parent control and written to the Page. If no parent control is found, the string "Control not found" is written.

Visual Basic
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


C#
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");
      }
}

J#
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.get_Parent();
        this.get_Response().Write("Parent of the text box is : " 
            + myControl2.get_ID());
    }
    else {
        this.get_Response().Write("Control not found");
    }
}//Button1_Click

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Page view tracker