C
Christophe Peillet
I have a base custom control called 'WebBox' that contains a single
EditableDesignerRegion. The contents of this EditableDesignerRegion are
stored in an ITemplate via a property name 'Content', and serialized as an
InnerProperty.
This all works as expected, renders properly, etc., but I can't figure out
how, in a control that inherits WebBox (such as AdvertisementWebBox,
SearchWebBox, etc.) to add controls to the ITemplate in code on the Server
Side. If I add things in the markup, as below, everything works fine (see
inner property names 'Content').
<CompanyUI:WebBox ID="SearchWebBox" runat="server" IconWidth="0"
SkinID="SearchBox"
Title="Search" TitleVisible="True" Width="180px">
<Content>
<div style="text-align: center">
<table border="0" cellpadding="0" cellspacing="0"
style="width: 100%">
<tr>
<td align="left" style="width: 130px" valign="top">
<CompanyUI:AdvancedTextBox ID="AdvancedTextBox1"
runat="server" LabelPosition="Bottom"
Width="130px"></CompanyUI:AdvancedTextBox></td>
<td align="center" valign="top">
<CompanyUI:AdvancedButton ID="SearchButton"
runat="server" Text="go" /></td>
</tr>
<tr>
<td align="left" colspan="2" style="width: 130px"
valign="top">
<CompanyUI:CompanyHyperLink
ID="AdvancedSearchLink" runat="server" Description="" LinkLeaderCssClass=""
LinkLeaderImageCssClass=""
LinkLeaderImageUrl="" NavigateUrl="~/AdvancedSearch.aspx"
TextResourceKey="AdvancedSearch">Advanced
Search</CompanyUI:CompanyHyperLink></td>
</tr>
</table>
</div>
</Content>
</CompanyUI:WebBox>
How can I do this in code in another specialized server control, though?
In the server control that inherits WebBox, I have tried the following, but
with no success.
protected override void OnPreRender(EventArgs e)
{
// Call underlying OnPreRender method
base.OnPreRender(e);
if (!(this.DesignMode))
{
// Clear WebBox .Content control collection
Control template = new Control();
base.Content.InstantiateIn(template);
// ToDo: How to add controls to an ITemplate in code?
template.Controls.Clear();
... // Add controls to collection
... template.Controls.Add(...) ...
}
}
I want WebBox as a generic control with an empty ITemplate, and in
specialized controls that inherit from it to add controls like Search boxes,
link listings, etc.
Any help on this would be appreciated.
EditableDesignerRegion. The contents of this EditableDesignerRegion are
stored in an ITemplate via a property name 'Content', and serialized as an
InnerProperty.
This all works as expected, renders properly, etc., but I can't figure out
how, in a control that inherits WebBox (such as AdvertisementWebBox,
SearchWebBox, etc.) to add controls to the ITemplate in code on the Server
Side. If I add things in the markup, as below, everything works fine (see
inner property names 'Content').
<CompanyUI:WebBox ID="SearchWebBox" runat="server" IconWidth="0"
SkinID="SearchBox"
Title="Search" TitleVisible="True" Width="180px">
<Content>
<div style="text-align: center">
<table border="0" cellpadding="0" cellspacing="0"
style="width: 100%">
<tr>
<td align="left" style="width: 130px" valign="top">
<CompanyUI:AdvancedTextBox ID="AdvancedTextBox1"
runat="server" LabelPosition="Bottom"
Width="130px"></CompanyUI:AdvancedTextBox></td>
<td align="center" valign="top">
<CompanyUI:AdvancedButton ID="SearchButton"
runat="server" Text="go" /></td>
</tr>
<tr>
<td align="left" colspan="2" style="width: 130px"
valign="top">
<CompanyUI:CompanyHyperLink
ID="AdvancedSearchLink" runat="server" Description="" LinkLeaderCssClass=""
LinkLeaderImageCssClass=""
LinkLeaderImageUrl="" NavigateUrl="~/AdvancedSearch.aspx"
TextResourceKey="AdvancedSearch">Advanced
Search</CompanyUI:CompanyHyperLink></td>
</tr>
</table>
</div>
</Content>
</CompanyUI:WebBox>
How can I do this in code in another specialized server control, though?
In the server control that inherits WebBox, I have tried the following, but
with no success.
protected override void OnPreRender(EventArgs e)
{
// Call underlying OnPreRender method
base.OnPreRender(e);
if (!(this.DesignMode))
{
// Clear WebBox .Content control collection
Control template = new Control();
base.Content.InstantiateIn(template);
// ToDo: How to add controls to an ITemplate in code?
template.Controls.Clear();
... // Add controls to collection
... template.Controls.Add(...) ...
}
}
I want WebBox as a generic control with an empty ITemplate, and in
specialized controls that inherit from it to add controls like Search boxes,
link listings, etc.
Any help on this would be appreciated.