views:

14

answers:

0

I have hundreds of legacy webform pages adding header and footer via a BasePage overriding Render

    protected override void Render(HtmlTextWriter writer)
    {
        RenderHeader(writer);
        base.Render(writer);
        RenderFooter(writer);
    }

New pages uses a MasterPage for the default behavior.

I would like to know if it's possible to add the asp:content control from the BasePage without changing every *.aspx?

I made a small test that's working as long there's no content in the aspx

public partial class OldPage : Page
{
    private MainContentTemplate mainContentTemplate;

    protected override void OnPreInit(EventArgs e)
    {
        Page.MasterPageFile = "~/Site.Master";

        mainContentTemplate = new MainContentTemplate();            
        AddContentTemplate("Main", mainContentTemplate);

        base.OnPreInit(e);
    }
}

public class MainContentTemplate : ITemplate
{
    #region ITemplate Members

    void ITemplate.InstantiateIn(Control container)
    {

        container.Controls.Add(new LiteralControl("Test string"));
    }

    #endregion
}

But as soon as i add something to the code in front I will receive: Content controls have to be top-level controls in a content page or a nested master page that references a master page.

I'm not sure but I think that overriding ControlCollection Controls might help, but I haven't find a solution.