ITemplate and ControlBuilder

Discussion in 'ASP .Net Building Controls' started by richard.szalay, Mar 26, 2007.

  1. 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?
     
    richard.szalay, Mar 26, 2007
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.