Skip to content

Instantly share code, notes, and snippets.

@dochoffiday
Last active October 12, 2018 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dochoffiday/0b04a92fc58f304de4184db39cf9df00 to your computer and use it in GitHub Desktop.
Save dochoffiday/0b04a92fc58f304de4184db39cf9df00 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Web.UI;
public static class ControlHelpers
{
public static IEnumerable<Control> FindControlsRecursive(this Control root, string regex)
{
foreach (Control child in root.Controls)
{
if (!string.IsNullOrWhiteSpace(child.ID))
{
if (Regex.Match(child.ID, regex).Success)
{
yield return child;
}
}
if (child.Controls.Count > 0)
{
foreach (Control c in FindControlsRecursive(child, regex))
{
yield return c;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment