Skip to content

Instantly share code, notes, and snippets.

@orjan
Created October 20, 2009 17:21
Show Gist options
  • Save orjan/214437 to your computer and use it in GitHub Desktop.
Save orjan/214437 to your computer and use it in GitHub Desktop.
using System;
using System.Web.UI;
namespace WebApplication.template
{
public class BasePage : Page
{
public BasePage()
{
HeaderControls = new ControlCollection(this);
FooterControls = new ControlCollection(this);
}
protected ControlCollection FooterControls { get; set; }
protected ControlCollection HeaderControls { get; set; }
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
HeaderControls.Add(LoadControl("controls/header.ascx"));
FooterControls.Add(LoadControl("controls/footer.ascx"));
}
protected override void Render(HtmlTextWriter writer)
{
RenderTemplate(HeaderControls, writer);
base.Render(writer);
RenderTemplate(FooterControls, writer);
}
private static void RenderTemplate(ControlCollection collection, HtmlTextWriter writer)
{
foreach (Control c in collection)
{
c.RenderControl(writer);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment