Persisting properties in templates and not the control itself

Discussion in 'ASP .Net Building Controls' started by Alessandro Zifiglio, Nov 9, 2003.

  1. 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
     
    Alessandro Zifiglio, Nov 9, 2003
    #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. JezB
    Replies:
    1
    Views:
    372
  2. JKop
    Replies:
    3
    Views:
    492
  3. recover
    Replies:
    2
    Views:
    828
    recover
    Jul 25, 2006
  4. cpnet

    Persisting control properties at design time

    cpnet, Apr 19, 2004, in forum: ASP .Net Building Controls
    Replies:
    15
    Views:
    290
    Jeffrey Tan[MSFT]
    May 10, 2004
  5. Alessandro Zifiglio

    Persisting properties in templates

    Alessandro Zifiglio, Nov 9, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    174
    Alessandro Zifiglio
    Nov 9, 2003
Loading...

Share This Page