ITemplate strange behaviuor

T

tremway

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
 

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top