This documentation is archived and is not being maintained.

Control.Parent Property

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

[Visual Basic]
Public Overridable ReadOnly Property Parent As Control
public virtual Control Parent {get;}
public: __property virtual Control* get_Parent();
public function get Parent() : Control;

Property Value

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.


[Visual Basic, C#] 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)
            Response.Write("Control not found.....")
         End If
   End Sub

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

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace