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>

// 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),
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 =


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

return null;

public class SampleControlTemplate
private ITemplate template;
public ITemplate Template
get { return template; }
set { template = value; }

public SampleControlTemplate()

Any thoughts?


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question