Which ASP.NET Controls Have Child Controls?

  • Thread starter Thread starter poi
  • Start date Start date
P

poi

In VS.NET 2003, I get intellisense if I do this:

LiteralControl literalControl = new LiteralControl();
literalControl.ID = "something";

literalControl.Controls.Add.....

And it compiles fine but I get an error saying that the LiteralControl
does not allow child controls.

So which controls *do* allow children, since VS.NET is not helping me?

Thanks.
 
The problem is, LiteralControl inherits from a class that has a Controls
property - so LiteralControl inherits it as well.

Container controls such as a Panel, PlaceHolder, and others have a Controls
collection you an manipulate.

Controls such as TextBox, Button, etc don't - and this just makes sense. A
button cannot have any controls within it - it is a button!

You just have to think about whether or not it really makes sense for a
control to have child controls.
 
That's a darned good question. I am just guessing here, but I would suspect
that any control which renders a tag can have Controls added to it. The
reason I believe this is that adding a Control to the Controls Collection of
a Server Control appends the child Control HTML in between the starting and
ending tags of the parent Control. A LiteralControl can be plain text,
without any tag at all. I suspect that this is why you can't add Controls to
its' Controls Collection. I would love to hear an authoritative answer to
this question, though.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 
And a good case in point... don't always rely on the grossly overrated
Intellisense.. ;)

Bill P.
 
Back
Top