Child controls disappearing

Discussion in 'ASP .Net Web Controls' started by Kelly, Oct 27, 2003.

  1. Kelly

    Kelly Guest

    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; }
    }
    }
     
    Kelly, Oct 27, 2003
    #1
    1. Advertising

  2. Kelly

    Oliver Guest

    Hi Kelly,

    Not sure, but is this the problem that Denis Bauer's free control is meant
    to solve?

    http://www.denisbauer.com/ASPNETControls/DynamicControlsPlaceholder.aspx

    "Problem:

    ASP.NET gives a developer the opportunity to programmatically add controls
    to a web form using ParentControl.Controls.Add(new Control());
    However, these controls are not persisted in any way thus having to be
    recreated for each subsequent request.

    Goal:
    To create a control that behaves like a placeholder but additionally handles
    recreating dynamic controls on subsequent requests.

    Procedure:
    I have created a custom control called DynamicControlsPlaceholder that
    derives from Placeholder and overrides Load- and SaveViewState.
    In SaveViewState, the control hierarchy is recursively traversed and the
    control type and ID persisted to a string
    In LoadViewState the persisted information is used to recreate the control
    tree to the state before."

    "Kelly" <> wrote in message
    news:...
    > 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; }
    > }
    > }
     
    Oliver, Oct 29, 2003
    #2
    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. Jerry Camel

    Disappearing Controls

    Jerry Camel, Feb 12, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    334
    Jerry Camel
    Feb 12, 2004
  2. =?Utf-8?B?Smlt?=

    User controls and disappearing values

    =?Utf-8?B?Smlt?=, Nov 10, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    460
    =?Utf-8?B?Smlt?=
    Nov 11, 2004
  3. Jeff Rodriguez
    Replies:
    23
    Views:
    1,201
    David Schwartz
    Dec 9, 2003
  4. Replies:
    0
    Views:
    220
  5. Donal McWeeney

    Mixing child properties and child controls - how?

    Donal McWeeney, Feb 10, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    135
    [MSFT]
    Feb 14, 2005
Loading...

Share This Page