Problem with collection property in custom server control

R

Rene Aichinger

Hi,
I've created a server control (it inherits from WebControl) wich has a
property of genertic collection type.
The type of the generic collection is NavigationItem, a little class I've
created...

The declaration of the collection property is that:

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public Collection<NavigationItem> Items
{
get
{
if (_items == null)
_items = new Collection<NavigationItem>();
return _items;
}
}

If I put the control on my ASPX page, the control renders fine. Also when I
create some items in that collection everything looks good.
When I change from from the design view to the source view, the tags for my
control looks like this:

<ctrls:TopNavigationPanel ID="TopNavigationPanel1" runat="server"
BackgroundUrl="img/bg_horizontal.gif">
<Items>
<ctrls:NavigationItem ControlText="My item" Selected="False" />
<ctrls:NavigationItem ControlText="My second item"
Selected="False" />
</Items>

Now if I change back to the design view, instead of my control I can see the
following error message:

'Items' could not be initialized. Details: 'Items' could not be added to the
collection. Details: The value "Controls.NavigationItem" is not of type
"Controls.NavigationItem" and cannot be used in this generic collection.
Parameter name: value

If I remove the items in the source view the control is displayed correctly
in the design view.
When I start my website the control also looks good, with or without items
in the collection. Only the Designer seems to dislikes this property if it
has items.

If I override the ToString method of the NavigationItem class and return
this.ControlText (ControlText is a string property of the NavigationItem
class) the error message in the design view changes to that:

[...] Details: The value "My item" is not of type "Controls.NavigationItem"
[...].

So I think the designer tries to add something wrong to the collection and
that fails... but I don't know, where I have made a mistake.

Maybe anyone of you can help me with that...?

I'm using Visual Studio 2005 Beta 2.

Thank you very much!
René
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top