Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Please: ITemplate propery being saved incorrectly -- Attributes usage incorrect?

Reply
Thread Tools

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

 
 
S.Sigal
Guest
Posts: n/a
 
      08-14-2004

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.







 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word document saved to SQL Server as Image - retrieves incorrectly K B ASP .Net 1 06-05-2006 04:05 PM
Saved Mail Gone and Sent Mail Not Being Saved Gregg Firefox 6 03-06-2006 02:13 AM
Please: ITemplate propery being saved incorrectly -- Attributes usage incorrect? S.Sigal ASP .Net Web Controls 0 08-14-2004 02:04 PM
Re: TabIndex propery not working as expected for Server controls Natty Gur ASP .Net 1 03-03-2004 04:09 PM
Disk Space being incorrectly reported rfdjr1@optonline.net Computer Support 2 12-17-2003 12:24 PM



Advertisments