foreach (Control ctrl in this.Controls)
{
TextBox tb = ctrl as TextBox;
if (tb != null)
{
// do something with TextBox tb ...
}
}
Note: do NOT try this:
foreach (TextBox tb in this.Controls) { ... }
This does not *filter* for textboxes, but tries to cast *all* controls to textboxes,
which will fail.
ArrayList textboxArray = new ArrayList();
foreach(Control control in this.Controls)
if ( control.GetType() == typeof( TextBox) )
textboxArray.Add( control );
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.