Context:
An AJAX Control Toolkit TabContainer
, where each TabPanel
is generated with code behind, and its ContentTemplate is a custom control.
The custom control corresponds to what goes directly in the TabPanel
's ContentTemplate
:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TabContentTemplateTest.ascx.cs" Inherits="WebGUI.Controls.TabContentTemplateTest" %>
<asp:Label runat="server" ID="TabText" />
And code behind:
public partial class TabContentTemplateTest : UserControl, ITemplate
{
public string Number { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
TabText.Text = Number;
}
public void InstantiateIn(Control container)
{
container.Controls.Add(this);
}
}
Creation (code behind of TabContainerTest
, having a TabContainer
named SamplesTabContainer
):
public string[] Numbers = { "zero", "one", "two", "three", "four" };
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
var tabContent = LoadControl("~/Controls/TabContentTemplateTest.ascx") as TabContentTemplateTest;
tabContent.Number = Numbers[i];
SamplesTabContainer.Tabs.Add(new TabPanel
{
HeaderText = i.ToString(),
ContentTemplate = tabContent
});
}
}
The problem is that the content (here simplified to a label) doesn't show.
How can I generate the custom control from ASPX as a ContentTemplate
and display it?
Setting the
TabPanel
'sOnDemandMode
toOnDemandMode.None
forces the addition of the controls right away, which makes them display.