Best approach for custom container control RRS feed

  • Question

  • User76497178 posted

    My basic question is, what are the pros/cons to these 2 approaches for creating a custom web server control that will contain wide-open markup in one of its properties:

    - Use templates for the property that will handle all of this content

    - Use ParseChildren(false) and just allow child controls to render themselves

    I was thinking that templates are more for expose extensibility for a certain portion of a control (like column header templates, etc), but it this case, where I'm creating a custom container sort of like Panel, etc, it doesn't seem to fit as well as the ParseChildren(false) approach.

    I took a look at the System.Web.UI.Panel class, and it looks like it takes the ParseChildren(false) approach, but perhaps templates offer some additional features that would make them work here as well.

    Any feedback would be appreciated.

    Monday, March 24, 2008 1:20 PM


  • User-1136466523 posted


    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    From your description, it seems that you want to create a custom container sort of like Panel, right?

    <o:p> </o:p>

    If so,why don’t you use PersistChildren(true) attribute for your custom server control?

    <o:p> </o:p>

    Since for panel controls or other container controls, they are used to persisting children controls. So you should parse the content as Child controls instead of attributes. And ‘PersistChildren(true)’ indicates that the contents in children control are persisted as server controls.

    <o:p> </o:p>



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 26, 2008 11:07 PM