Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   Please: ITemplate propery being saved incorrectly -- Attributes usage incorrect? (http://www.velocityreviews.com/forums/t774027-please-itemplate-propery-being-saved-incorrectly-attributes-usage-incorrect.html)

S.Sigal 08-14-2004 02:04 PM

Please: ITemplate propery being saved incorrectly -- Attributes usage incorrect?
 
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.Persis tenceMode.InnerProperty),
System.ComponentModel.DesignerSerializationVisibil ity(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.Persis tenceModeInnerProperty),
//System.ComponentModel.DesignerSerializationVisibil ity(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.Persis tenceMode.InnerProperty),
System.ComponentModel.DesignerSerializationVisibil ity(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.Persis tenceMode.InnerProperty),
System.ComponentModel.DesignerSerializationVisibil ity(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.Heade r = 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.Persis tenceMode.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.







All times are GMT. The time now is 05:02 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.