Control.Parent 属性 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取对页 UI 层次结构中服务器控件的父控件的引用。
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.ControlPublic Overridable ReadOnly Property Parent As Control属性值
对服务器控件的父控件的引用。
- 属性
示例
以下示例将页面上myControl1的新Control对象设置为方法调用中指定的FindControl控件。 如果调用返回控件,代码将使用 Parent 该属性来标识包含的 myControl1控件。 如果父控件存在,则字符串“文本框的父级为”与 ID 父控件的属性串联,并写入该 Page属性。 如果未找到父控件,则写入字符串“找不到控件”。
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
注解
每当请求页面时,该页上的服务器控件层次结构将生成。 此属性允许你确定该层次结构中当前服务器控件的父控件,并对其进行编程。