Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / August 2005

Tip: Looking for answers? Try searching our database.

ITemplate strange behaviuor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tremway@yahoo.com - 27 Aug 2005 17:48 GMT
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
intrader - 29 Aug 2005 22:38 GMT
On Sat, 27 Aug 2005 09:48:01 -0700, tremway wrote:

> Hi all,
> I've found something strange that I cannot explain to myself. See the
[quoted text clipped - 100 lines]
>
> Trem
I have not followed the details of templates, but in the June edition of
the MSDN magazine, y found an article related to templates.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.