Please: ITemplate propery being saved incorrectly -- Attributes usage incorrect?

Discussion in 'ASP .Net Web Controls' started by S.Sigal, Aug 14, 2004.

  1. S.Sigal

    S.Sigal Guest

    HELP!

    Have a problem to do with Attributes and serialization: currently it's too greedy and is serializing
    to the Html/XML even blank/null ITemplates properties -- rather than not serializing nothing
    when the ITemplate == null.

    Let me explain:

    //SCENARIO 1 -- WORKS
    First let's look at a scenario that works: I have an Itemplate that I want to expose as a property
    of a webcontrol:
    [
    System.ComponentModel.DefaultValue(null),
    System.ComponentModel.NotifyParentProperty(true),
    System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty),
    System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
    ]
    public ITemplate TestTemplate {get {return _TestTemplate;}set {_TestTemplate = value;}}
    private ITemplate _TestTemplate = null;

    Perfect.
    I muck around in the IDE, change other properties, and the IDE forces a save to the
    XML/HTML of the control.

    The result looks like:

    <CC:MYCONTROL BackColor="red"/>

    No referance to TestTemplate because TestTemplate is null.
    Good -- that's what we want.



    //SCENARIO 2 -- DOESNT WORK:
    Now -- Let's look at what is not working:
    Because I am designing a control that has many Template objects (eg: RssChannelTitle,
    RssChannelDescription, RssItemTitle, RssItemDescription, footer, etc.....)
    I don't want them as primary (root level) Properties of the control, but as sub-properties within an
    ExpandableObject, and so that the output xml/html would look more like:

    <CC:MYCONTROL>
    <TEMPLATES>
    <HEADER>
    My Custom Header Goes here!!!
    </HEADER>
    <FOOTER>
    My custom footer goes here...
    </FOOTER>
    </TEAMPLATES>
    </CC:MYCONTROL>


    In other words (codewise):
    System.ComponentModel.DefaultValue(null), /*Q: The right DefaultValue to give when not a null? */
    System.ComponentModel.NotifyParentProperty(true),
    System.Web.UI.PersistenceMode(System.Web.UI.PersistenceModeInnerProperty),
    //System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    public Control_Templates Templates{get {return _Templates;}}
    private _Templates = new Control_Templates();
    where:

    [TypeConverter(typeof(ExpandableObjectConverter))]
    Control_Templates {
    [
    System.ComponentModel.DefaultValue(null),
    System.ComponentModel.NotifyParentProperty(true),
    System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty),
    System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
    ]
    public ITemplate Header {get {return _Header;}set {_Header = value;}}
    private ITemplate _Header = null;

    [[[[[[[[[[[[[[[[...many more templates defs go here...]]]]]]]]]]]]]]]]

    [
    System.ComponentModel.DefaultValue(null),
    System.ComponentModel.NotifyParentProperty(true),
    System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty),
    System.ComponentModel.DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
    ]
    public ITemplate Footer {get {return _Footer;}set {_Footer = value;}}
    private ITemplate _Footer = null;
    }



    The final result of this is that the XML generated looks like:

    <CC:MYCONTROL>
    <TEMPLATES>
    <HEADER>
    </HEADER>
    <FOOTER>
    </FOOTER>
    </TEAMPLATES>
    </CC:MYCONTROL>

    even though all the ITemplates are NULL, rather than

    <CC:MYCONTROL>
    <TEMPLATES>
    </TEAMPLATES>
    </CC:MYCONTROL>

    Which is causing rendering issues because during my Render() I wrote:

    if (this.Templates.Header==null){this.Templates.Header = new Template_Header();}
    if (this.Templates.Header!=null){
    TemplateContainer_Header oHeader = new TemplateContainer_Header(this, this.oChannel);
    this.Controls.Add(oHeader);
    this.Templates.Header.InstantiateIn(oHeader);
    }

    But that doesn't work.
    Now, because it has serialized the
    property to being <HEADER></HEADER> it says that it has a header -- just that it's blank -- and
    therefore never instantiates the builtin/default one.


    The check in Render() would now have to be something like
    if (this.Templates.Header.Controls.Count == 0) {...}
    or something like that, which is absurd coding.


    It would be best to figure out how to ensure that it doesn't write blank ITemplates as properties in
    the xml....just like it can do
    when the template is a base level property.

    In other words, HELP!


    (And Thank you!)




    PS:
    Tried so far -- modifying the attributes on one of the sub-properties :


    [
    System.ComponentModel.DefaultValue(null),
    System.ComponentModel.NotifyParentProperty(true),
    System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty),
    TemplateContainer(typeof(TemplateContainer_Item))
    ]
    public ITemplate Footer {get {return _Footer;}set {_Footer = value;}}
    private ITemplate _Footer = null;

    but to no avail:

    I have tried removing the DesignerSerializationVisibility.Content:
    I have tried removing the NotifiyParentProperty -- didn't work.
    I have tried setting NotifyParentProperty to false... didn't work.
    I have tried taking off the DefaultProperty(null)...didn't help either.

    Out of ideas.
     
    S.Sigal, Aug 14, 2004
    #1
    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. Natty Gur
    Replies:
    1
    Views:
    1,921
    Marshal Antony
    Mar 3, 2004
  2. Andrey Tarasevich

    IE ignores table cell height propery - why?

    Andrey Tarasevich, Aug 8, 2005, in forum: HTML
    Replies:
    6
    Views:
    30,243
    mbstevens
    Aug 9, 2005
  3. K B
    Replies:
    1
    Views:
    806
    Winista
    Jun 5, 2006
  4. keithb
    Replies:
    4
    Views:
    7,862
    starsky163
    Oct 17, 2008
  5. S.Sigal
    Replies:
    0
    Views:
    147
    S.Sigal
    Aug 14, 2004
Loading...

Share This Page