Collection Designer in Composite Controls

A

Alexander Popov

i have following sample Control

[ParseChildren(true)]
[PersistChildren(true)]
public class MyControl: System.Web.UI.Control
{
MyCollection values_ = new MyCollection ();

[PersistenceMode(PersistenceMode.InnerProperty),

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public MyCollection Values
{
get
{
return values_;
}
}
protected override void OnInit(EventArgs e)
{
base.OnInit (e);
//...
}

protected override void Render(HtmlTextWriter writer)
{
base.Render (writer);
//...
}
}

//Collection:
public class MyCollection : CollectionBase
{
public MyItem this[int index]
{
get
{
return this.InnerList[index] as MyItem ;
}
}

public MyItem Add(MyItem item)
{
this.InnerList.Add(item);
return item;
}
}
//Item - its NOT control, same as Columns in Datagrid
public class MyItem
{
protected string prop_;
public string Prop
{
get{return prop_;}
set{prop_ = value;}
}
}



it's work Perfect if I fill control by Hand in ASPX :

<cc1:MyControl id=MyControl1 runat="server" >
<Values>
<cc1:MyItem Prop="value1"/>
<cc1:MyItem Prop="value2"/>
<cc1:MyItem Prop="value3"/>
</Values>
</cc1:MyControl>
Now I want to have ability fill control with same structure
in designer.When I click "..." button in property grid on Values row -
Collection Editor is Open and I may do add|remove my Items.But when I click
"OK", in ASPX control stay empty

<cc1:MyControl id=MyControl1 runat="server" >
</cc1:MyControl>

Much more, if control have existing items in aspx view, it's
deleted.Whats wrong?
 
S

Sky

I think its misuse of the Attributes you are attaching.
Try taking off the
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

and see if it updates.
 

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,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top