Click to See Complete Forum and Search --> : page controls


StyM
January 28th, 2004, 10:07 PM
Hello and Good Day.

may i know how i can iterate through all the server controls that my aspx page contains?
for example.
my test.aspx page contains 3 server side controls.

i want i my code behind to iterate through all these 3 controls.
how can this be done???
i tried Page.Controls but id didnt work for me, or just dont know how.

Thanks for help.

StyM
January 29th, 2004, 01:17 AM
just found a solution.

ControlCollection _coll = _page.Controls;
foreach(Control con in _coll)
{
if ( con.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlForm") )
{
ControlCollection _formColl = con.Controls;
foreach(Control _formControl in _formColl)
{
if ( _formControl.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox") )
{
TextBox _txtBox = (TextBox)_formControl;
_txtBox.Text = "hello";
}
}
}
}