Design time doesn't update when changing collection

Discussion in 'ASP .Net Building Controls' started by pedrobernabeu@hotmail.com, Oct 18, 2005.

  1. Guest

    I have a custom control with a ListItemCollection. If I add items by
    hand in the aspx and switch to design time view, everything works fine.
    However if I add items through the Collection Editor, the control
    doesn't update until I change something in the aspx and change to
    design view. However, if you try to update a DropDownList with the
    collection editor, the control updates as soon as you change something
    in the Collection Editor.

    Anybody knows what's wrong with this code?

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.ComponentModel.Design;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;


    namespace MyComponents
    {
    [Serializable]
    [ParseChildren(true, "Items")]
    public class TestControl : WebControl, INamingContainer
    {
    private ListItemCollection _items;

    [DefaultValue(null),
    PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    public ListItemCollection Items {
    get { return _items; }
    }

    public override ControlCollection Controls {
    get {
    EnsureChildControls();
    return base.Controls;
    }
    }

    public TestControl() : base(HtmlTextWriterTag.Div)
    {
    _items = new ListItemCollection();
    }

    protected override void CreateChildControls()
    {
    Controls.Add(new LiteralControl("-- TestControl --<br>"));
    for (int i = 0; i < _items.Count; i++){
    LiteralControl l = new LiteralControl(_items.Text + "<br>");
    Controls.Add(l);
    }
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
    foreach(Control ctrl in Controls){
    ctrl.RenderControl(writer);
    }
    }

    }
    }
    , Oct 18, 2005
    #1
    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. James Doran
    Replies:
    2
    Views:
    593
    James Doran
    Jun 15, 2004
  2. flamesrock
    Replies:
    8
    Views:
    438
    Hendrik van Rooyen
    Nov 24, 2006
  3. Øyvind Isaksen
    Replies:
    1
    Views:
    948
    Øyvind Isaksen
    May 18, 2007
  4. Matt Winward
    Replies:
    0
    Views:
    525
    Matt Winward
    Mar 20, 2008
  5. David Keenan

    Custom collection design time support

    David Keenan, Oct 9, 2003, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    148
    David Keenan
    Oct 13, 2003
Loading...

Share This Page