Composite Control Designer

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?
 
T

Teemu Keiski

Hi,

additionally specify the proeprty with NotifyParentProperty(true) attribute.
Does that help at all?
 
B

BMukes

Please take a look at the Server Control Collection Properties Solutions,
Problems MVP Advice Requested post.
Or
Go to
http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm
.. At the web site you can download source code that will probably get you
further along with your problem.
Brian
Teemu Keiski said:
Hi,

additionally specify the proeprty with NotifyParentProperty(true) attribute.
Does that help at all?

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
http://blogs.aspadvice.com/joteke



Alexander Popov said:
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?
 
L

LucaP

"Alexander Popov" <[email protected]> ha scritto nel messaggio
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?

I solved using ParseChildren(false).
If you set it to true, the nested elements are used as properties.
If you set it to false, the nested elements are used as child controls
(that's what you want...).
Bye.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top