Persisting collection data of a webcontrol when leaving the collection editor in VS2005

Discussion in 'ASP .Net Building Controls' started by mehdi.mousavi@gmail.com, May 6, 2006.

  1. Guest

    Hi folks,
    I'm developing a WebControl, that has got a property that's supposed to
    return a collection of data. Whenever I try to populate the mentioned
    collection under the visual designer, the items I add to the collection
    are not displayed in the .aspx file.

    Here's what I would like to have, when an item named "txt1" with value
    "val1" is added in the collection editor:

    <wcl:MyList ID="MyList1" runat="server" Items-Capacity="4">
    <wcl:MyItem Text="txt1" Value="val1" />
    </wcl:MyList>

    However, the

    <wcl:MyItem Text="txt1" Value="val1" />

    line is not added to the file, after closing the collection editor.
    Another amazing aspect of this control is the "Items-Capacity" property
    that's being concatenated to the above-declaration. I've got no idea
    what it is, too! Here's some code-snippet that may help to pinpoint the
    problem.


    [ToolboxData("<{0}:MyList runat=server></{0}:MyList>")]
    [ToolboxBitmap(typeof(MyList), "WebCtrlLib.MyList.ico")]
    [AspNetHostingPermission(SecurityAction.Demand, Level =
    AspNetHostingPermissionLevel.Minimal)]
    [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
    AspNetHostingPermissionLevel.Minimal)]
    [DefaultProperty("Items")]
    [ParseChildren(true, "Items")]
    [Designer(typeof(MyListContainerControlDesigner))]
    public class MyList: WebControl, INamingContainer
    {
    //removed for brevity

    [Category("Misc")]
    [Description("The collection of items in the list.")]

    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Editor(typeof(MyItemCollectionEditor), typeof(UITypeEditor))]
    [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    public MyItemCollection Items
    {
    get
    {
    if(m_coll == null)
    {
    m_coll = new MyItemCollection();
    if(IsTrackingViewState)
    ((IStateManager)m_coll).TrackViewState();
    }

    return m_coll;
    }
    }
    }

    public abstract class StateManagedCollectionBase<T>: CollectionBase,
    IViewState, IStateManager where T: class
    {
    /*
    public void Add(T item)
    public void Remove(int nIndex)
    public void Remove(T item)
    public T this[int index]*/
    }

    public class MyItemCollection: StateManagedCollectionBase<MyItem>
    {
    }

    class MyItemCollectionEditor: CollectionEditor
    {
    public MyItemCollectionEditor(Type type): base(type)
    {
    }

    protected override bool CanSelectMultipleInstances()
    {
    return false;
    }

    protected override Type CreateCollectionItemType()
    {
    return typeof(MyItem);
    }
    }

    public class MyListContainerControlDesigner: ContainerControlDesigner
    {
    public override DesignerAutoFormatCollection AutoFormats
    {
    //removed for brevity
    }
    }


    Any help would be highly appreciated.

    Cheers,
    M.Mousavi
    , May 6, 2006
    #1
    1. Advertising

  2. I don't have code readily available, but I believe you need to point the
    collection's control collection to the MyList control collection in order to
    persist it in the aspx page.

    -Tim

    <> wrote in message
    news:...
    > Hi folks,
    > I'm developing a WebControl, that has got a property that's supposed to
    > return a collection of data. Whenever I try to populate the mentioned
    > collection under the visual designer, the items I add to the collection
    > are not displayed in the .aspx file.
    >
    > Here's what I would like to have, when an item named "txt1" with value
    > "val1" is added in the collection editor:
    >
    > <wcl:MyList ID="MyList1" runat="server" Items-Capacity="4">
    > <wcl:MyItem Text="txt1" Value="val1" />
    > </wcl:MyList>
    >
    > However, the
    >
    > <wcl:MyItem Text="txt1" Value="val1" />
    >
    > line is not added to the file, after closing the collection editor.
    > Another amazing aspect of this control is the "Items-Capacity" property
    > that's being concatenated to the above-declaration. I've got no idea
    > what it is, too! Here's some code-snippet that may help to pinpoint the
    > problem.
    >
    >
    > [ToolboxData("<{0}:MyList runat=server></{0}:MyList>")]
    > [ToolboxBitmap(typeof(MyList), "WebCtrlLib.MyList.ico")]
    > [AspNetHostingPermission(SecurityAction.Demand, Level =
    > AspNetHostingPermissionLevel.Minimal)]
    > [AspNetHostingPermission(SecurityAction.InheritanceDemand, Level =
    > AspNetHostingPermissionLevel.Minimal)]
    > [DefaultProperty("Items")]
    > [ParseChildren(true, "Items")]
    > [Designer(typeof(MyListContainerControlDesigner))]
    > public class MyList: WebControl, INamingContainer
    > {
    > //removed for brevity
    >
    > [Category("Misc")]
    > [Description("The collection of items in the list.")]
    >
    > [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    > [Editor(typeof(MyItemCollectionEditor), typeof(UITypeEditor))]
    > [PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    > public MyItemCollection Items
    > {
    > get
    > {
    > if(m_coll == null)
    > {
    > m_coll = new MyItemCollection();
    > if(IsTrackingViewState)
    > ((IStateManager)m_coll).TrackViewState();
    > }
    >
    > return m_coll;
    > }
    > }
    > }
    >
    > public abstract class StateManagedCollectionBase<T>: CollectionBase,
    > IViewState, IStateManager where T: class
    > {
    > /*
    > public void Add(T item)
    > public void Remove(int nIndex)
    > public void Remove(T item)
    > public T this[int index]*/
    > }
    >
    > public class MyItemCollection: StateManagedCollectionBase<MyItem>
    > {
    > }
    >
    > class MyItemCollectionEditor: CollectionEditor
    > {
    > public MyItemCollectionEditor(Type type): base(type)
    > {
    > }
    >
    > protected override bool CanSelectMultipleInstances()
    > {
    > return false;
    > }
    >
    > protected override Type CreateCollectionItemType()
    > {
    > return typeof(MyItem);
    > }
    > }
    >
    > public class MyListContainerControlDesigner: ContainerControlDesigner
    > {
    > public override DesignerAutoFormatCollection AutoFormats
    > {
    > //removed for brevity
    > }
    > }
    >
    >
    > Any help would be highly appreciated.
    >
    > Cheers,
    > M.Mousavi
    >
    Tim Dot NoSpam, May 19, 2006
    #2
    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. john_teague

    persisting collection in a custom datagrid

    john_teague, Dec 6, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    387
    john_teague
    Dec 6, 2005
  2. Stylus Studio
    Replies:
    0
    Views:
    640
    Stylus Studio
    Aug 3, 2004
  3. Øyvind Isaksen
    Replies:
    1
    Views:
    950
    Øyvind Isaksen
    May 18, 2007
  4. Phillyboy123

    Complex properties (Button) not persisting in webcontrol

    Phillyboy123, Nov 18, 2003, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    168
    Sam Fields
    Jan 15, 2004
  5. Phillyboy123

    Complex properties (Button) not persisting in webcontrol

    Phillyboy123, Nov 19, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    137
    Phillyboy123
    Nov 19, 2003
Loading...

Share This Page