public static void FindControlRecursive(Control control, String controlId, ref Control matchingControl)
{
//Keep looking for more controls until control is found, if found, immediately exit
if (matchingControl == null)
{
foreach (Control c in control.Controls)
{
//If match not found, make another recursive call
if (c.ID != controlId)
{
FindControlRecursive(c, controlId, ref matchingControl);
//Stop immediately if match is found
if (matchingControl != null)
{
break;
}
}
else
{
//Match found, update ref parameter
matchingControl = c;
}
}
}
else
{
return;
}
}