C
cmartinbot
Hello and TIA.
I have a very simple server control that has one property that needs
to be rendered in an ITemplate. I can't seem to figure out why it
won't render with the <%# Container.Value%> syntax inside the
declarative template.
The container control for the template is being instantiated
correctly.
It should be said that this control lives within a Repeater
ItemTemplate which I suspect is the reason for this not working.
Relative Code:
---
[ParseChildren(true)]
public class CustomData : WebControl, INamingContainer
{
private ITemplate content;
private string currentValue;
protected override void CreateChildControls()
{
if( !ChildControlsCreated )
{
IDataRetriever retriever = DataRetriever.Create(dataType, article,
forceFetch, label);
currentValue = retriever.ValueString;
InstantiateTemplate(content);
ChildControlsCreated = true;
}
}
private void InstantiateTemplate(ITemplate template)
{
if(template == null)
{
template = new DefaultTemplate( currentValue );
}
DataContainer container = new DataContainer(currentValue);
template.InstantiateIn(container);
Controls.Add( container );
}
#region Properties
[PersistenceMode( PersistenceMode.InnerProperty )]
[TemplateContainer(typeof(DataContainer))]
[Browsable(false)]
public ITemplate Content
{
get { return content; }
set { content = value; }
}
#endregion
}
}
public class DataContainer : Control, INamingContainer
{
private string value;
public DataContainer(string value)
{
this.value = value;
}
public string Value
{
get { return value; }
set { this.value = value; }
}
}
ASPX:
---
<cc1:CustomData ID="CustomData2" DataType="ShortString" runat="server"
Label="City">
<Content>(CityIsHereButNotShowing[<%# Container.Value%>])</Content>
</cc1:CustomData>
Please help!!!
Thanks again,
Chris Martin
I have a very simple server control that has one property that needs
to be rendered in an ITemplate. I can't seem to figure out why it
won't render with the <%# Container.Value%> syntax inside the
declarative template.
The container control for the template is being instantiated
correctly.
It should be said that this control lives within a Repeater
ItemTemplate which I suspect is the reason for this not working.
Relative Code:
---
[ParseChildren(true)]
public class CustomData : WebControl, INamingContainer
{
private ITemplate content;
private string currentValue;
protected override void CreateChildControls()
{
if( !ChildControlsCreated )
{
IDataRetriever retriever = DataRetriever.Create(dataType, article,
forceFetch, label);
currentValue = retriever.ValueString;
InstantiateTemplate(content);
ChildControlsCreated = true;
}
}
private void InstantiateTemplate(ITemplate template)
{
if(template == null)
{
template = new DefaultTemplate( currentValue );
}
DataContainer container = new DataContainer(currentValue);
template.InstantiateIn(container);
Controls.Add( container );
}
#region Properties
[PersistenceMode( PersistenceMode.InnerProperty )]
[TemplateContainer(typeof(DataContainer))]
[Browsable(false)]
public ITemplate Content
{
get { return content; }
set { content = value; }
}
#endregion
}
}
public class DataContainer : Control, INamingContainer
{
private string value;
public DataContainer(string value)
{
this.value = value;
}
public string Value
{
get { return value; }
set { this.value = value; }
}
}
ASPX:
---
<cc1:CustomData ID="CustomData2" DataType="ShortString" runat="server"
Label="City">
<Content>(CityIsHereButNotShowing[<%# Container.Value%>])</Content>
</cc1:CustomData>
Please help!!!
Thanks again,
Chris Martin