Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > ITemplate container will not render.

Reply
Thread Tools

ITemplate container will not render.

 
 
cmartinbot
Guest
Posts: n/a
 
      02-12-2007
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

 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      02-14-2007
Have you overridden DataBind method to recreate child controls?

Something like:

public override void DataBind()
{
ChildControlsCreated = false;
CreateChildControls();
ChildControlsCreated = true;
base.DataBind();

}

You don't also need to check ChildControlsCreated in CreateChildControls,
calling EnsureChildControls will do that. And in CreateChildControls the
first line should be Controls.Clear();


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


"cmartinbot" <> wrote in message
news: ups.com...
> 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
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net Building Controls 0 04-01-2005 04:59 PM
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net 0 04-01-2005 04:58 PM
Newbie:Access custom Itemplate(not datagrid/repeater/datalist) control values on postback Luhar Powell via .NET 247 ASP .Net Web Controls 0 04-01-2005 04:56 PM
DropDownList / <select> value not setting in Itemplate cosine... zero ASP .Net 0 06-11-2004 06:52 PM
Itemplate not accepting postback in data-bound templated control cosine... zero ASP .Net 0 06-09-2004 06:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57