Web User Controls with multiple child elements

  • Thread starter Thread starter Douglas
  • Start date Start date
D

Douglas

Hi all,

Here's a simplified example of my problem. I'm looking to have code
like this on an .aspx page:

<cc:Cameras runat="server">
<Camera Name="EOS 400D" />
<Camera Name="EOS 350D" />
</cc:Cameras>

And render HTML something like this:

<ul>
<li>EOS 400D</li>
<li>EOS 350D</li>
</ul>

I've defined a camera element CameraElement to represent each <Camera /
and a private List<CameraElement> cameras so that I can store and
manipulate the list. However, I don't know how to get the
CameraElement objects into the list.

The best I have managed is this mangled property on Cameras:

public CameraElement Camera
{
set { cameras.Add(value); }
}

This seems suspect to me, and I can't find an example of how to do it
properly. How do I add the CameraElement objects to the List without
abusing a setter?

Thanks,
Douglas
 
First of all, why are you not using the BulletedList control? Is there
something you plan to have your UserControl do that the BulletedList control
cannot do?
 
First of all, why are you not using the BulletedList control? Is there
something you plan to have your UserControl do that the BulletedList control
cannot do?

It's a simplified example, I don't plan to use bullets. The actual
page will have a series of divs with content populated using
information from the elements inside my control. I'd like to learn how
to extract information from the content supplied to my control through
the aspx page.

Is source code for the BulletedList, or something similar, available?
Then I can at least see how it does it.

Douglas
 
I don't know if the code for BulletedList is available, but a great book
that I know gives examples and teaches you how to do it is:


Cheers Nathan, will have a look for it.
 
Back
Top