ITemplate and ControlBuilder



My question in its simplest form is this. How can I have the ASP.NET
below map the "SomeTemplate" template to an ITemplate property without
using ParseChildren(true) - in fact, I need to have
ParseChildren(false) because other children are complex (with
attributes and such).

<!-- ASP.NET -->
<cl:CustomControl runat="server">
<SomeTemplate><%# Eval("tada") %></SomeTemplate>
</cl:CustomControl>

// Control code
public class CustomControl : Control
{
public ITemplate SomeTemplate { get; set; }
}

I have attempted to use a ControlBuilder, but have had significant
issues in getting it to handle an ITemplate. The closest I've come is
the below sample, but even it freaks out the ASP.NET compiler with an
error "No overload for method __BuildControl__control6 takes '0'
arguments". I know I'm getting close because the code behind is
compiling the content as a template.

[PersistChildren(true), ParseChildren(false),
ControlBuilder(typeof(SampleControlBuilder))]
public class SampleControl : Control, IParserAccessor
{
private ITemplate sampleTemplate;

public ITemplate SampleTemplate
{
get { return sampleTemplate; }
set { sampleTemplate = value; }
}

#region IParserAccessor Members

void IParserAccessor.AddParsedSubObject(object obj)
{
if (obj is SampleControlTemplate)
this.sampleTemplate =
((SampleControlTemplate)obj).Template;
}

#endregion
}

public class SampleControlBuilder : TemplateBuilder
{
public override Type GetChildControlType(string tagName,
System.Collections.IDictionary attribs)
{
if (tagName.Equals("sampletemplate",
StringComparison.InvariantCultureIgnoreCase))
return typeof(SampleControlTemplate);

return null;
}
}

[ControlBuilder(typeof(TemplateBuilder))]
public class SampleControlTemplate
{
private ITemplate template;
public ITemplate Template
{
get { return template; }
set { template = value; }
}

public SampleControlTemplate()
{
}
}

Any thoughts?

.



Relevant Pages

  • Re: apply an ItemTemplate dinamically
    ... databound control. ... Such ITemplate property is designed to be configured ... the template, ... a lot of work to design and manage layout's rendering. ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • RE: Adding controls to EditableDesignerRegion/ITemplate in code.
    ... something similar to a ControlCollection to add objects inside the template ... The ITemplate class is included below. ... /// that child controls and templates belong to. ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Template control error
    ... private ITemplate _template; ... public TestPanel Panel ... public virtual ITemplate Template ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Using ITemplate as property of a custom control
    ... I tried to create a class that implements ITemplate and create the ... property there but I'm getting this annoying error that I can't ... with the content inside of the template? ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)

Loading