Thursday, March 22, 2012

What is the collection object that hold all the server controls on a page?

I tried to loop through all the controls of a aspx page by calling

foreach (Control ctl in this.Controls)
{
...
}

I found only label are in the Controls collection. How can I obtain the collection for all other server controls on the page like TextBox, DropDownList, ..., etc.Hey,

I do it by form, try:

foreach (Control ctrl in ((HtmlForm)this.FindControl("form1")).Controls)
{

}

Regardless, it doesn't bring back only labels, but other controls. Try converting them to the appropriate type before using them.

Brian
COOL! that works. Thank you Brian.

0 comments:

Post a Comment