System.Web.UI Namespace Control Class
Searches the current naming container for the specified server control.
1. Searches the current naming container for a server control with the specified id parameter.
2. This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.
The following example demonstrates using the FindControl method.
NOTE: This example shows how to use one of the overloaded versions of FindControl. For other examples that might be available, see the individual overload topics.
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 |
|
C# |
VB |
Control Members