ASP.NET Templated User Controls - Limit child controls allowable within a templated control

Discussion in 'ASP .Net' started by JohnyStyles@gmail.com, May 29, 2006.

  1. Guest

    I have a templated user control which looks like this:

    -----------------------------------------------------------------
    <uc:MyUserControl runat=server>
    <TemplateProperty>

    </TemplateProperty>
    </uc:MyUserControl>
    -----------------------------------------------------------------

    Currently i can drop any html/web controls/user controls into
    TemplateProperty. I then handle these inside of my user control, in
    the PreRender, I do run:
    _templateProperty.InstantiateIn(aPlaceHolderInsideUserControl);

    This all works. Very nice, allows for great content encapsulation.

    Now, what I would like to do next is limit what controls are allowable
    INSIDE of the TemplateProperty. An example would be only allowing
    'asp:Label' to be used, or as in my case, another usercontrol which
    I've created.

    So idealy, once one types:
    -----------------------------------------------------------------
    <Template Property>
    <[ctrl-space]
    -----------------------------------------------------------------

    intelisense only allows you to populate the Template Property with
    controls that are allowable, i.e. asp:Label, or a another specified
    user control, or something of that nature.

    ASP.NET actually already does this with some webcontrols. for an
    example, look at:
    -----------------------------------------------------------------
    <asp:DataGrid runat=server>
    <Columns>
    </Columns>
    </asp:DataGrid>
    -----------------------------------------------------------------

    inside of the Templated Property, Columns, one can only choose from:
    <asp:BoundColumn />
    <asp:ButtonColumn />
    <asp:EditCommandColumn />
    <asp:HyperLinkColumn />
    <asp:TemplateColumn />

    Any other control inserted in <Columns> will cause compile errors:
    Error 4 Validation (ASP.Net): Text is not allowed between the opening
    and closing tags for element Columns'.

    I'd like to have this same functionality with my controls. Any help
    would be greatly appreciated!

    Thanx Much,
    John Pequeno
    .... just another Computer Engineer
     
    , May 29, 2006
    #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. RA Scheltema
    Replies:
    3
    Views:
    424
    RA Scheltema
    Jan 6, 2004
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,211
    David Schwartz
    Dec 9, 2003
  3. Rasmus Johansen
    Replies:
    3
    Views:
    415
    VirGin
    Oct 18, 2007
  4. debartsa
    Replies:
    1
    Views:
    380
    John Saunders
    Apr 9, 2004
  5. Replies:
    0
    Views:
    220
Loading...

Share This Page