Finding all controls in an ASP.NET Panel?
It boils down to enumerating all the controls in the control hierarchy:
IEnumerable<Control> EnumerateControlsRecursive(Control parent)
{
foreach (Control child in parent.Controls)
{
yield return child;
foreach (Control descendant in EnumerateControlsRecursive(child))
yield return descendant;
}
}
You can use it like this:
foreach (Control c in EnumerateControlsRecursive(Page))
{
if(c is TextBox)
{
// do something useful
}
}
You can loop thru the panels controls
foreach (Control c in MyPanel.Controls)
{
if (c is Textbox) {
// do something with textbox
} else if (c is Checkbox) {
/// do something with checkbox
}
}
If you have them nested inside, then you'll need a function that does this recursively.