ITemplate strange behaviuor

Discussion in 'ASP .Net Building Controls' started by tremway@yahoo.com, Aug 27, 2005.

  1. Guest

    Hi all,
    I've found something strange that I cannot explain to myself. See the
    code below:

    [ParseChildren(true)]
    public class MyControl : Control, INamingContainer
    {
    public MyControl() : base() {}

    private HeaderTemplateCreator _header;
    public HeaderTemplateCreator Header
    {
    get { return _header;}
    set { _header=value; }
    }

    private FooterTemplate _footer;
    public FooterTemplate Footer
    {
    get { return _footer; }
    set { _footer=value; }
    }

    protected override void CreateChildControls()
    {
    Controls.Clear();

    if (Header!=null)
    {
    Header.InstantiateIn(this);
    }

    if (Footer!=null)
    {
    Footer.InstantiateIn(this);
    }
    }
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    public class HeaderTemplateCreator : ITemplate
    {
    public void InstantiateIn(Control container)
    {
    container.Controls.Add(new HeaderTemplate());
    }
    }

    public class HeaderTemplate : Control, INamingContainer
    {
    public HeaderTemplate() : base()
    {
    }
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    public class FooterTemplate : Control, INamingContainer, ITemplate
    {
    public FooterTemplate() : base()
    {
    }

    public void InstantiateIn(Control container)
    {
    container.Controls.Add(this);
    }
    }

    I place this control in .asxp as follows:

    <uc:MyControl id="mc" runat="server">
    <header>
    </header>
    <footer>
    blah-blah<br>
    <asp:Label ID="label1" Runat="server" text="some text" />
    </footer>
    </uc:MyControl>

    This works properly. But when I try to put some content in "header" tag
    like:

    <uc:MyControl id="mc" runat="server">
    <header>
    SOME_TEXT_HERE
    </header>
    <footer>
    blah-blah<br>
    <asp:Label ID="label1" Runat="server" text="some text" />
    </footer>
    </uc:MyControl>

    I get the following error:
    Parser Error Message: Literal content ('SOME_TEXT_HERE') is not allowed
    within a 'HeaderTemplateCreator'.

    This is pretty strange to me as I cannot see any major difference
    between HeaderTemplate (+HeaderTemplateCreateor) and FooterTemplate
    classes. If someone can explain this to me I will be very grateful.
    Thanks.

    Trem
    , Aug 27, 2005
    #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. cosine... zero
    Replies:
    0
    Views:
    639
    cosine... zero
    Jun 9, 2004
  2. cosine... zero
    Replies:
    0
    Views:
    762
    cosine... zero
    Jun 11, 2004
  3. Andrea Williams

    Datagrid binding to Itemplate Dropdown box

    Andrea Williams, Aug 5, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,391
    Andrea Williams
    Aug 5, 2004
  4. =?Utf-8?B?QW1pbmU=?=

    Itemplate viewstate

    =?Utf-8?B?QW1pbmU=?=, Jan 17, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,827
    Karl Seguin
    Jan 17, 2005
  5. andy

    strange behaviuor when assigning string

    andy, Nov 11, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    102
Loading...

Share This Page