Persisting properties in templates and not the control itself

  • Thread starter Alessandro Zifiglio
  • Start date
A

Alessandro Zifiglio

hi,

I'm creating a custom web control and I'm pretty much stuck in templates.
Everything is working great, I have no problems, even if the documentation
on templates is not very clear most of the time and this being my first
custom control I had to scratch my head plenty before I could implement this
feature into my custom control. Ok now I need to implement style properties
in my template.

To really cut this short, I need my style properties to be properties that
you can set in the template itself like :
<mycontrol:name id="bla" runat="server">
<HeaderTemplate border="bla" backcolor="bla" ... .></HeaderTemplate>
</mycontrol:name>

as of now i can make these style properties show in the control itself as
subproperties like PropertyName-SubPropertyName for example :

<mycontrol:name id="bla" . . . runat="server"
Headerstyle-BorderColor="darkolivegreen">

<HeaderTemplate border="bla" backcolor="bla" ... .></HeaderTemplate>

</mycontrol:name>


HeaderStyle being a public expandable property declared in mycontrol class.
Now HeaderStyle is presented as PropertyName-SubPropertyName in mycontrol.
However this is not what i want and vs.net does this for me when i prefix
PersistenceMode(PersistenceMode.InnerProperty) to the property HeaderStyle.
Whereas if i prefixed
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
vs.net creates an element for that particular property and displays all sub
properties within it. Again this is not what i want.

What i want is for the properties to show in my custom template. I have
tried declaring the property Headerstye in my template class and then
prefixing PersistenceMode(PersistenceMode.InnerProperty) to my templates
declaration in mycontrol class which didnt do the trick. I've done various
experiments and i must say my efforts were useless ;)

Like if any of you has looked at the datagrid, its got templates and within
the template you can specify the style attributes there like :

<asp:DataGrid id="DataGrid1" . . . . .runat="server">
<HeaderStyle BackColor="#FFC0C0"></HeaderStyle>
<ItemStyle BackColor="#FFFFC0"></ItemStyle>
<FooterStyle BackColor="#C0C0FF"></FooterStyle>
</asp:DataGrid>


In the docs i see an example under PersistenceMode Enumeration which looks
like what i might want to do but its incomplete EEEEEEEEEEE.. .ks!!!

[Visual Basic]

<PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(GetType(TemplateItem))> Public Property MessageTemplate()
As ITemplate
Get
Return _messageTemplate
End Get
Set(ByVal Value As ITemplate)
_messageTemplate = Value
End Set
End Property

[C#]
[PersistenceMode(PersistenceMode.InnerProperty),
TemplateContainer(typeof(TemplateItem))]
public ITemplate MessageTemplate {
get {
return _messageTemplate;
}
set {
_messageTemplate = value;
}
}



How do i associate the properties to persist . . .it does not elaborate any
further. I have looked into almost anything i could get my hands on and i
always come to a dead end.

I'm hoping that someone has already been able to achieve this. I have looked
on the asp.net forums too, nothing. I'm desperate. Hopefully if nobody knows
the answer to this maybe someone from microsoft might want to join in and
let me on this well kept secret .. hhaha ;)

This is a very basic implementation anybody might want to achieve when using
templates. And there is no article, content, documentation related to
properties in templates.

Thanks
Alessandro
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top