Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding aTabPanel dynamically and making its ContentTemplate from ASPX
    text
    copied!<p>Context:</p> <p>An AJAX Control Toolkit <code>TabContainer</code>, where each <code>TabPanel</code> is generated with code behind, and its ContentTemplate is a custom control.</p> <p>The custom control corresponds to what goes directly in the <code>TabPanel</code>'s <code>ContentTemplate</code>:</p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TabContentTemplateTest.ascx.cs" Inherits="WebGUI.Controls.TabContentTemplateTest" %&gt; &lt;asp:Label runat="server" ID="TabText" /&gt; </code></pre> <p>And code behind:</p> <pre><code>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); } } </code></pre> <p>Creation (code behind of <code>TabContainerTest</code>, having a <code>TabContainer</code> named <code>SamplesTabContainer</code>):</p> <pre><code>public string[] Numbers = { "zero", "one", "two", "three", "four" }; protected void Page_Load(object sender, EventArgs e) { for (int i = 0; i &lt; 5; i++) { var tabContent = LoadControl("~/Controls/TabContentTemplateTest.ascx") as TabContentTemplateTest; tabContent.Number = Numbers[i]; SamplesTabContainer.Tabs.Add(new TabPanel { HeaderText = i.ToString(), ContentTemplate = tabContent }); } } </code></pre> <p>The problem is that the content (here simplified to a label) doesn't show.</p> <p><strong>How can I generate the custom control from ASPX as a <code>ContentTemplate</code> and display it?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload