Composite Control Designer

Discussion in 'ASP .Net Building Controls' started by Alexander Popov, May 26, 2004.

  1. 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?
    Alexander Popov, May 26, 2004
    #1
    1. Advertising

  2. Alexander Popov

    Teemu Keiski Guest

    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" <> wrote in message
    news:...
    > 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?
    >
    >
    Teemu Keiski, May 26, 2004
    #2
    1. Advertising

  3. Alexander Popov

    BMukes Guest

    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" <> wrote in message
    news:%...
    > 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" <> wrote in message
    > news:...
    > > 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?
    > >
    > >

    >
    >
    BMukes, May 28, 2004
    #3
  4. Alexander Popov

    LucaP Guest

    "Alexander Popov" <> ha scritto nel messaggio
    news:...
    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.
    LucaP, Jun 4, 2004
    #4
    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. sleigh
    Replies:
    1
    Views:
    2,685
    sleigh
    Feb 12, 2004
  2. Chad
    Replies:
    0
    Views:
    219
  3. Showjumper

    Composite Control Designer Question

    Showjumper, Feb 26, 2005, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    169
  4. Dimitar Dimitrov

    Composite control and designer-generated code for nested events

    Dimitar Dimitrov, Apr 14, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    115
    Dimitar Dimitrov
    Apr 14, 2005
  5. Mike

    Composite vs non composite Controls

    Mike, Mar 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    261
    Sundararajan
    Mar 11, 2005
Loading...

Share This Page