.NET Framework Class Library
ControlFindControl Method (String)

Searches the current naming container for a server control with the specified id parameter.

Namespace:   System.Web.UI
Assembly:  System.Web (in System.Web.dll)
Public Overridable Function FindControl ( _
	id As [%$TOPIC/486wc64h_en-us_VS_110_1_0_0_0_0%] _
) As [%$TOPIC/486wc64h_en-us_VS_110_1_0_0_0_1%]
public virtual [%$TOPIC/486wc64h_en-us_VS_110_1_0_1_0_0%] FindControl(
	[%$TOPIC/486wc64h_en-us_VS_110_1_0_1_0_1%] id
virtual [%$TOPIC/486wc64h_en-us_VS_110_1_0_2_0_0%]^ FindControl(
	[%$TOPIC/486wc64h_en-us_VS_110_1_0_2_0_1%]^ id
abstract FindControl : 
        id:[%$TOPIC/486wc64h_en-us_VS_110_1_0_3_0_0%] -> [%$TOPIC/486wc64h_en-us_VS_110_1_0_3_0_1%]  
override FindControl : 
        id:[%$TOPIC/486wc64h_en-us_VS_110_1_0_3_0_2%] -> [%$TOPIC/486wc64h_en-us_VS_110_1_0_3_0_3%]
public function FindControl(
	id : [%$TOPIC/486wc64h_en-us_VS_110_1_0_4_0_0%]
) : [%$TOPIC/486wc64h_en-us_VS_110_1_0_4_0_1%]


Type: SystemString

The identifier for the control to be found.

Return Value

Type: System.Web.UIControl
The specified control, or if the specified control does not exist.

Use FindControl to access a control from a function in a code-behind page, to access a control that is inside another container, or in other circumstances where the target control is not directly accessible to the caller. This method will find a control only if the control is directly contained by the specified container; that is, the method does not search throughout a hierarchy of controls within controls. For information about how to find a control when you do not know its immediate container, see How to: Access Server Controls by ID.


The following example defines a Button1_Click event handler. When invoked, this handler uses the FindControl method to locate a control with an ID property of TextBox2 on the containing page. If the control is found, its parent is determined using the Parent property and the parent control's ID is written to the page. If TextBox2 is not found, "Control Not Found" is written to the page.

Security noteSecurity Note

This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

   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)
      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");
         // Get control's parent.
         Control myControl2 = myControl1.Parent;
         Response.Write("Parent of the text box is : " + myControl2.ID);
         Response.Write("Control not found");
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1