in

ASP.NET Weblogs

Andy Smith's Blog

Page.RegisterStartupScript('Andy', 'MetaBuilders_WebControls_GainKnowledge();');

default templates

I got a comment on my my last post about default templates:

I'm writing a templated control that I want to support a "default template" - that is, a control that supports templates but can render a sensible default look and feel without forcing the user to write a template declaration.

this is something that you can already do easily. In your control, when you would be calling the ITemplate, do something like this:

if ( myTemplateProperty != null ) {
    myTemplateProperty.InstantiateIn(myContainer);
} else {
    createDefaultLook(myContainer);
}

createDefaultLook simply adds the default controls you want.

RuntimeTemplate is more for page developers, who may not have access to your control's source code, that want to create templates via code.

Comments

 

Kevin Dente said:

Oops, I didn't mean to imply that you couldn't accomplish it now. But that approach results in multiple rendering paths, which I was trying to avoid. And if you have multiple templates (Item, Alternating Item, Header, Footer, ...), you get multiple multiple rendering paths. Having one, and programmatically creating the template, just seems cleaner to me.
July 1, 2003 2:12 PM

Leave a Comment

(required)  
(optional)
(required)  
Add