Du kan måske bruge denne her som inspiration:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace PageControls
{
public class InnerPage : WebControl
{
private ITemplate m_HeaderTemplate;
private ITemplate m_ContentTemplate;
private ITemplate m_NavigationTemplate;
[PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(TemplateControl))]
public ITemplate HeaderTemplate
{
get { return m_HeaderTemplate; }
set { m_HeaderTemplate = value; }
}
[PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(TemplateControl))]
public ITemplate ContentTemplate
{
get { return m_ContentTemplate; }
set { m_ContentTemplate = value; }
}
[PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(TemplateControl))]
public ITemplate NavigationTemplate
{
get { return m_NavigationTemplate; }
set { m_NavigationTemplate = value; }
}
protected override void CreateChildControls()
{
Table table = new Table();
table.BorderStyle = BorderStyle.Solid;
table.BorderWidth = 1;
table.GridLines = GridLines.Both;
TableRow row = new TableRow();
TableCell cell = new TableCell();
row.Cells.Add(cell);
cell.ColumnSpan = 2;
if (m_HeaderTemplate != null)
{
m_HeaderTemplate.InstantiateIn(cell);
}
table.Rows.Add(row);
row = new TableRow();
cell = new TableCell();
row.Cells.Add(cell);
if (m_NavigationTemplate == null)
{
m_NavigationTemplate = new DefaultNavigationTemplate();
}
m_NavigationTemplate.InstantiateIn(cell);
row = new TableRow();
table.Rows.Add(row);
row.Cells.Add(cell);
cell = new TableCell();
if (m_ContentTemplate != null)
{
m_ContentTemplate.InstantiateIn(cell);
}
row.Cells.Add(cell);
Controls.Add(table);
base.CreateChildControls();
}
protected void Page_Load(object sender, EventArgs e)
{
string s = sender.ToString();
}
}
public class DefaultNavigationTemplate : ITemplate
{
protected GridView m_NavigationTable;
public void InstantiateIn(Control container)
{
m_NavigationTable = new GridView();
m_NavigationTable.DataSource = CreateDataSource();
m_NavigationTable.DataBind();
container.Controls.Add(m_NavigationTable);
}
protected virtual DataTable CreateDataSource()
{
DataTable data = new DataTable();
data.Columns.Add("Text", typeof(string));
data.Columns.Add("Link", typeof(string));
DataRow row = data.NewRow();
row["text"] = "Blah";
row["link"] = "
http://www.google.dk"; data.Rows.Add(row);
row = data.NewRow();
row["text"] = "Yuhah";
row["link"] = "
http://www.dr.dk"; data.Rows.Add(row);
return data;
}
}
}
Kan bruges på en side sådan her:
<ctr:InnerPage ID="InnerPage1" runat="server">
<HeaderTemplate>
<asp:Label Text="HEADER" runat="server" ID="lblHeader"></asp:Label>
</HeaderTemplate>
<ContentTemplate>
<asp:Label ID="Label1" Text="CONTENT" runat="server"></asp:Label>
</ContentTemplate>
</ctr:InnerPage>
Mvh