pedrobernabeu
Usenet Archive
- Joined
- Oct 18, 2005
- Messages
- 2
- Reaction score
- 0
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. I can't understand why because 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 what I need to add to this code to make the control to update when changing something with the collection editor?
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);
}
}
}
}
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. I can't understand why because 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 what I need to add to this code to make the control to update when changing something with the collection editor?
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);
}
}
}
}