Last active
October 12, 2018 20:09
-
-
Save dochoffiday/0b04a92fc58f304de4184db39cf9df00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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