CompositeControl design time list problems when altering HTML (Objectdoes not support target type)

Discussion in 'ASP .Net' started by Matt Winward, Mar 25, 2008.

  1. Matt Winward

    Matt Winward Guest

    I'm really stuck with a Composite Control and I could really do with
    some pointers if anyone's willing.

    My control has a public property as follows:

    /// <summary>
    /// Gets a list of all the menu items (not including Home or Login).
    /// </summary>
    [Category("Behaviour")]
    [Browsable(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    [NotifyParentProperty(true)]
    [ReadOnly(true)]
    public List<MainMenuItem> MenuItems
    {
    get
    {
    if (_menuitems == null) _menuitems = new List<MainMenuItem>();
    return _menuitems;
    }
    }

    When CreateChildControls() fires, I go through this list and populate
    the main menu accordingly. Each MainMenuItem is, in turn, another
    Composite Control.

    If I drop a MainMenu control onto the design-time canvas, it goes on
    fine. I can then go to MenuItems in the properties pain, click on the
    ellipsis and add a load of MainMenuItem controls and the control
    updates itself with these new controls.

    The problem is that if I go to the HTML and change anything, like
    removing one of the menu items, for example, and then go back to the
    Design view, the control throws the following error:

    'MenuItems' could not be initialized. Details: 'MenuItems' could not
    be added to the collection. Details: Object does not match target
    type.

    I've been trawling the net for days but can't work out why this error
    is appearing and what I need to do to rectify it.

    Any help would be greatly appreciated!!


    Matt
    Matt Winward, Mar 25, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Polansky
    Replies:
    0
    Views:
    732
    Daniel Polansky
    Oct 11, 2004
  2. Boot2TheHead
    Replies:
    2
    Views:
    485
    Boot2TheHead
    Sep 6, 2007
  3. Matt Winward
    Replies:
    0
    Views:
    526
    Matt Winward
    Mar 20, 2008
  4. MC

    CompositeControl fails to display in Design view

    MC, Oct 11, 2007, in forum: ASP .Net Building Controls
    Replies:
    11
    Views:
    1,006
    Steven Cheng[MSFT]
    Oct 15, 2007
  5. Eidolon

    Altering Design-time html of custom control

    Eidolon, Jan 23, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    189
    Alessandro Zifiglio
    Jan 25, 2004
Loading...

Share This Page