ControlCollection in ASPX page

  • Thread starter Thread starter Lubo¹ ©lapák
  • Start date Start date
L

Lubo¹ ©lapák

Hi,
I need from ControlCollection on aspx page select all TextBoxes.
How can I do it?

Thanks
 
Hi,

One thing you can do is iterate in the Page.Controls checking for the
control's type and storing them in an array


Cheers,
 
I don't know how to check it for control's type.
Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

One thing you can do is iterate in the Page.Controls checking for the
control's type and storing them in an array


Cheers,
 
Lubo¹ ©lapák said:
Hi,
I need from ControlCollection on aspx page select all TextBoxes.
How can I do it?

Thanks

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.

Hans Kesting
 
Hi,

try this:


ArrayList textboxArray = new ArrayList();
foreach(Control control in this.Controls)
if ( control.GetType() == typeof( TextBox) )
textboxArray.Add( control );


cheers,
 
Back
Top