I am a danish programmer living in Bangkok.
Read more about me @ rasmus.rummel.dk.
Webmodelling Home > ASP.NET > C# Utility Functions > Control - Find Recursive

Control - Find Recursive

Finding controls recursively is I think difficult enough and used frequently enough that I don't understand it have not been implemented in the Control class. FindRecursive should really be an extension function, however to be consistent I implement it as a standard static function in my utility library (then I also know which function I am using should Microsoft decide to implement it as well).


  • Example
    • I use the FindRecursive function in jewelpit.com in a Page base class to search for controls in child Page classes.
  • Example Code
    • Control controlToFind = Utils.Control.FindRecursive(this"ControlID");

The FindRecursive function :

public static Control FindRecursive(Control pParent, string pControlID)
	Control ctrl = pParent.FindControl(pControlID);
	if (ctrl == null)
		foreach (System.Web.UI.Control child in pParent.Controls)
			ctrl = FindRecursive(child, pControlID);
			if (ctrl != null)
	return ctrl;


You can comment without logging in
 B  U  I  S 
Words: Chars: Chars left: