Professional Web Applications Themes

Persisting collection data of a webcontrol when leaving the collection editor in VS2005 - ASP.NET Building Controls

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 ...

  1. #1

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

    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.Inheritance Demand, Level =
    AspNetHostingPermissionLevel.Minimal)]
    [DefaultProperty("Items")]
    [PChildren(true, "Items")]
    [Designer(typeof(MyListContainerControlDesigner))]
    public class MyList: WebControl, INamingContainer
    {
    //removed for brevity

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

    [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
    [Editor(typeof(MyItemCollectionEditor), typeof(UITypeEditor))]
    [PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
    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

    mehdi.mousavi@gmail.com Guest

  2. #2

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

    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

    <mehdi.mousavi> wrote in message
    news:1146916556.141170.287090g10g2000cwb.googlegr oups.com...
    > 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.Inheritance Demand, Level =
    > AspNetHostingPermissionLevel.Minimal)]
    > [DefaultProperty("Items")]
    > [PChildren(true, "Items")]
    > [Designer(typeof(MyListContainerControlDesigner))]
    > public class MyList: WebControl, INamingContainer
    > {
    > //removed for brevity
    >
    > [Category("Misc")]
    > [Description("The collection of items in the list.")]
    >
    > [DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content)]
    > [Editor(typeof(MyItemCollectionEditor), typeof(UITypeEditor))]
    > [PersistenceMode(PersistenceMode.InnerDefaultProper ty)]
    > 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 Guest

Similar Threads

  1. Persisting a collection property in a custom datagrid
    By jcteague@gmail.com in forum ASP.NET Building Controls
    Replies: 0
    Last Post: December 5th, 09:09 PM
  2. Object Collection Editor
    By Sergio Florez M. in forum ASP.NET Building Controls
    Replies: 1
    Last Post: December 8th, 01:27 PM
  3. Persisting Collection in Component
    By Shawn B. in forum ASP.NET Building Controls
    Replies: 0
    Last Post: October 4th, 09:33 PM
  4. WebControl Designer Problem using Custom Collection
    By Todd Lucas via .NET 247 in forum ASP.NET Building Controls
    Replies: 2
    Last Post: May 28th, 02:34 PM
  5. Collection Editor
    By Juan Romero in forum ASP.NET Building Controls
    Replies: 0
    Last Post: December 30th, 09:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139