Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_professional thread: Custom control and collection property


Message #1 by "Paul Pelletier" <Paul_Pelletier@b...> on Thu, 15 Nov 2001 15:41:02 -0500
Hi!

I'm trying to have declare a property of a typed Collection in a custom
control and I was able to do that without too much problem. I am somewhat
puzzled by the fact that although I can add objects to it with the designer,
I cannot see the objects in the HTML view. All I see is something like:

<cc1:style id="Style2" runat="server" CSSFiles="(Collection)"
CSSFiles-Count="4"></cc1:style>

public class Style : WebControl
{
    private CSSInfoCollection cssInfoCollection_ = new CSSInfoCollection();

    public Style() {
        /*cssInfoCollection_.Add(new CSSInfo("/CUIDResources/baancom.css",
true));
        cssInfoCollection_.Add(new CSSInfo("/CUIDResources/calendar.css",
false));
        cssInfoCollection_.Add(new CSSInfo("/CUIDResources/content.css",
false));
        cssInfoCollection_.Add(new CSSInfo("/CUIDResources/menu.css",
false));
        cssInfoCollection_.Add(new CSSInfo("/CUIDResources/tabnav.css",
false)); */
    }

    [Category("CSS"),
    Browsable(true),
    Bindable(true),
    Description(""),
    DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
    ]
    public CSSInfoCollection CSSFiles {
        get { return cssInfoCollection_; }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        foreach (CSSInfo cssInfo in CSSFiles) {
            RenderCSS(writer, cssInfo);
        }
    }

}

Also, I wanted to have predefined objects already present in the list so I
added to the collection in the constructor. It seems to be fine ni the
designer but when I access the collection in my Render method, the
modifications I make with the designer are no longer correct.

Does anyone know what I might do wrong?
Thanks!
Paul



  Return to Index