Get Child Controls at design-time

Discussion in 'ASP .Net Building Controls' started by WALDO, Oct 22, 2004.

  1. WALDO

    WALDO Guest

    I have a Webcontrol that was supposed to act like a panel control. I
    manipulated a TemplatedControlDesigner to make an "Edit mode". I save my
    template to the controls collection during design-time. Then I use
    GetPersistInnerHtml with ControlPersister to push the controls
    collection back to the aspx page. It works very well after edit mode.

    My problem is initialization. My control won't pick up the inner tags
    from the html in the aspx on the first go-round. Since it didn't pick
    them up, it pushes blank back out to the aspx, thus clearing my inner
    html. I've been fiddling with ParseChildren and PersistChildren and
    overriding my Controls property, setting the PersistenceMode and
    DesignerSerializationVisibility attributes all day. I can't quite find
    the right combination. This thing gets them perfectly during runtime.

    I need to know how to get them at design time. Any Ideas?

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    WALDO, Oct 22, 2004
    #1
    1. Advertising

  2. WALDO

    WALDO Guest

    OK I figured it out.

    I approached it from a different angle. I said, "Well if
    System.Web.UI.WebControls.Table can do it, why am I having a problem?"

    I looked at the TableDesigner class and saw that it wasn't doing
    anything special, so I took a look at Table itself.

    I saw that it used
    ParseChildren(True, "Rows"), DefaultProperty("Rows")
    and didn't specify PersistChildren.

    I tried to do the same substituting "Controls" for "Rows". I got an
    error in design-time stating that the "Controls" property could not be
    programmatically set at design-time.

    So what did the Rows property on Table do? It ultimately is a surrogate
    property for the Controls Property. It returns a TableRowsCollection
    which inherits from ControlCollection. So basically it is the Controls
    Property being worked on by proxy.

    A-ha! :)

    OK, so what If I made a surrogate property called Content?
    All it did was return the Controls property. Would that work as
    expected? The answer is a resounding yes!

    [VB.Net]
    <ParseChildren(True, "Content"), PersistChildren(False), _
    DefaultProperty("Content"), Designer(GetType(MyDesigner))> _
    Public Class MyControl
    Inherits WebControl

    'Collect Controls from innerHtml, hide from UI/code.
    <PersistenceMode(PersistenceMode.InnerDefaultProperty), _
    MergableProperty(False), _
    Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> _
    Public Readonly Property Content As ControlCollection
    Get
    Return Me.Controls
    End Get
    End Property

    End Class


    One of the weird things about this was setting PersistChildern to false.
    Intellisense states 'true to persist the child controls as server
    control tags; otherwise, false' which seems contradictory to what I
    wanted, but after thinking about it, I guess that worked out OK.

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    WALDO, Oct 26, 2004
    #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. Jeff Rodriguez
    Replies:
    23
    Views:
    1,091
    David Schwartz
    Dec 9, 2003
  2. Pradeep Kumar C

    Building child controls on Design Time

    Pradeep Kumar C, Jun 30, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    137
    Steven Cheng[MSFT]
    Jun 30, 2004
  3. Replies:
    0
    Views:
    195
  4. Replies:
    1
    Views:
    174
    Teemu Keiski
    Dec 8, 2005
  5. Replies:
    1
    Views:
    178
    Teemu Keiski
    Dec 8, 2005
Loading...

Share This Page