K
Kelly
I've created a WebControl (that inherits from WebControl) that has
child controls that need to be persisted in the HTML. They seem to be
rendered initially at design-time, but then if I change something
about the parent control, all my inner controls are lost. I've seen
numerous other posts about this issue, but none of the solutions seems
to work. I've tried every combonation of ideas and I'm still running
into the same problem. If anyone has had success with this any advice
would be greatly appreciated!
Here is my parent control: (some code is omitted)
[ToolboxData("<{0}:NotesButton runat=server></{0}:NotesButton>"),
Designer(typeof(NotesButtonDesigner)),
ParseChildren(false),
PersistChildren(true)]
public class NotesButton : WebControl, IPostBackDataHandler
{
private NotesLineItem _line1 = new NotesLineItem();
[PersistenceMode(PersistenceMode.InnerDefaultProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public NotesLineItem Line1
{
get { return _line1; }
set { _line1 = value; }
}
}
//Here is the child
[TypeConverter(typeof(ExpandableObjectConverter))]
public class NotesLineItem
{
private string _label = string.Empty;
private string _value = string.Empty;
[NotifyParentProperty(true)]
public string Label
{
get { return _label; }
set { _label = value; }
}
[NotifyParentProperty(true)]
public string Value
{
get { return _value; }
set { _value = value; }
}
}
child controls that need to be persisted in the HTML. They seem to be
rendered initially at design-time, but then if I change something
about the parent control, all my inner controls are lost. I've seen
numerous other posts about this issue, but none of the solutions seems
to work. I've tried every combonation of ideas and I'm still running
into the same problem. If anyone has had success with this any advice
would be greatly appreciated!
Here is my parent control: (some code is omitted)
[ToolboxData("<{0}:NotesButton runat=server></{0}:NotesButton>"),
Designer(typeof(NotesButtonDesigner)),
ParseChildren(false),
PersistChildren(true)]
public class NotesButton : WebControl, IPostBackDataHandler
{
private NotesLineItem _line1 = new NotesLineItem();
[PersistenceMode(PersistenceMode.InnerDefaultProperty),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public NotesLineItem Line1
{
get { return _line1; }
set { _line1 = value; }
}
}
//Here is the child
[TypeConverter(typeof(ExpandableObjectConverter))]
public class NotesLineItem
{
private string _label = string.Empty;
private string _value = string.Empty;
[NotifyParentProperty(true)]
public string Label
{
get { return _label; }
set { _label = value; }
}
[NotifyParentProperty(true)]
public string Value
{
get { return _value; }
set { _value = value; }
}
}