On May 10, 12:44 am, nos...@nospam.sss (John Dalberg) wrote:
> The textbox is in the div collection but the div collection itself is
> getting an exception. This exception is only visible inside the debugger
> and because of this exception, the foreach ignores the div and moves along
> with the rest of the Page's collection. I can't look in the div collection
> if the Page can't see the div control.
John,
to look in the div collection I think you can do the following
foreach (Control c in this.Controls)
{
IterateThroughChildren(c);
....your code here...
}
void IterateThroughChildren(Control parent)
{
foreach (Control c in parent.Controls)
{
Response.Write(c.ClientID);
if (c.Controls.Count > 0)
{
IterateThroughChildren(c);
}
}
}
you can also try to FindControl("myDiv"), and cast it to
HtmlGenericControl.
I'm not sure about the origin of exception, I think, it's something
related to the control's life cycle - need to look in MSDN
Hope it helps