Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Persisting collection data of a webcontrol when leaving the collection editor in VS2005

Reply
Thread Tools

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

 
 
mehdi.mousavi@gmail.com
Guest
Posts: n/a
 
      05-06-2006
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")]
[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(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

 
Reply With Quote
 
 
 
 
Tim Dot NoSpam
Guest
Posts: n/a
 
      05-19-2006
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

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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")]
> [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(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
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Řyvind Isaksen ASP .Net 1 05-18-2007 09:24 AM
ANN: New low-cost XML Editor, XSLT Editor, XSLT Debugger, DTD/Schema Editor Stylus Studio Java 0 08-03-2004 03:53 PM
Complex properties (Button) not persisting in webcontrol Phillyboy123 ASP .Net Building Controls 1 01-15-2004 07:55 PM
Complex properties (Button) not persisting in webcontrol Phillyboy123 ASP .Net Web Controls 0 11-19-2003 02:20 PM



Advertisments