Control.Parent Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a reference to the server control's parent control in the page control hierarchy.
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
Property Value
A reference to the server control's parent control.
- Attributes
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 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
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.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기