Question: I need to get a control [textbox,label,button ...etc] from my page by it's ID using reflection 

In my case I have a class that all other system pages inherit from it and this class is override the onload event to change some properties to some controls

like set the visibility state for textbox by it's name but as I don't have the control direct on the page as I may have it on content place holder in master page so I couldn't use findcontrol method also I think recursive function to find the control will take too much time

So **I try to do it with refelection to find a control with its name** then change the visable or enable state for it

I used the FieldInfo class but doesn't work with me

```
FieldInfo fi = this.GetType().GetField("ControlID", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase);

```

Any help !

Answer: 
Have you tried [FindControl](http://msdn.microsoft.com/en-us/library/system.web.ui.control.findcontrol%28v=VS.100%29.aspx)

```
  Control myControl = this.FindControl("TextBox2");
  if(myControl !=null)
  {
       // Do Stuff
  }

```
Here's very useful extension method to get child controls recursively:

```
public static IEnumerable<Control> GetChildControls(this Control control)
{
    var children = (control.Controls != null) ? control.Controls.OfType<Control>() : Enumerable.Empty<Control>();
    return children.SelectMany(c => GetChildControls(c)).Concat(children);
}

```

Usage:

```
IEnumerable<Control> allChildren = parent.GetChildControls();

```