Skip to main content
.NET Framework Class Library
ControlParent Property

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)
Syntax
<[%$TOPIC/27f1syz2_en-us_VS_110_1_0_0_0_0%](False)> _
<[%$TOPIC/27f1syz2_en-us_VS_110_1_0_0_0_1%](False)> _
Public Overridable ReadOnly Property Parent As [%$TOPIC/27f1syz2_en-us_VS_110_1_0_0_0_2%]
[[%$TOPIC/27f1syz2_en-us_VS_110_1_0_1_0_0%](false)]
[[%$TOPIC/27f1syz2_en-us_VS_110_1_0_1_0_1%](false)]
public virtual [%$TOPIC/27f1syz2_en-us_VS_110_1_0_1_0_2%] Parent { get; }
[[%$TOPIC/27f1syz2_en-us_VS_110_1_0_2_0_0%](false)]
[[%$TOPIC/27f1syz2_en-us_VS_110_1_0_2_0_1%](false)]
public:
virtual property [%$TOPIC/27f1syz2_en-us_VS_110_1_0_2_0_2%]^ Parent {
	[%$TOPIC/27f1syz2_en-us_VS_110_1_0_2_0_3%]^ get ();
}
[<[%$TOPIC/27f1syz2_en-us_VS_110_1_0_3_0_0%](false)>]
[<[%$TOPIC/27f1syz2_en-us_VS_110_1_0_3_0_1%](false)>]
abstract Parent : [%$TOPIC/27f1syz2_en-us_VS_110_1_0_3_0_2%] with get
[<[%$TOPIC/27f1syz2_en-us_VS_110_1_0_3_0_3%](false)>]
[<[%$TOPIC/27f1syz2_en-us_VS_110_1_0_3_0_4%](false)>]
override Parent : [%$TOPIC/27f1syz2_en-us_VS_110_1_0_3_0_5%] with get

Property Value

Type: System.Web.UIControl
A reference to the server control's parent control.
Remarks

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.

Examples

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.


   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
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");
      }
}
Version Information

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0
Platforms

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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