System.Web.UI Namespace Control Class
Searches the current naming container for a control with the specified id.
[ VB ]
Overloads Overridable Public Function FindControl ( _
ByVal id As String _
) As Control
[ C# ]
public virtual Control FindControl (
string id
);
[ C++ ]
public: virtual Control* FindControl (
String* id
);
[ JScript ]
public function FindControl (
id : String
) : Control;
- id
- The identifier for the control to find.
The specified control, or a null reference ( Nothing in Visual Basic ) if the specified control does not exist.
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 Control.FindControl Overload List