Sign in
|
Join
in
-[Danny Chen]- Blog of an ASP.NET QA tester (blog)
Microsoft Bloggers (group)
(Entire Site)
ASP.NET Weblogs
Home
Blogs
This Blog
Home
About
Syndication
RSS
Atom
Comments RSS
Recent Posts
I have a new blog: http://blogs.msdn.com/dannychen
IE7 Beta and VWD Style Builder.
Top results for the loading control challenge.
We are Hiring.
A custom control challenge - make a page loading control that just works.
Tags
Code
me
About Me
Who is Danny Chen?
Archives
March 2006
(3)
February 2006
(3)
January 2006
(3)
December 2005
(5)
November 2005
(1)
October 2005
(3)
August 2005
(1)
April 2005
(3)
March 2005
(1)
-[Danny Chen]- Blog of an ASP.NET QA tester
Tips and info about Site Navigation, ImageMap, Menu and other cool ASP.NET v2.0 features.
Code Listing for 1/27/2006
TemplateLibrary.cs
using
System;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Collections.Generic;
namespace
MSSamples
{
///
<summary>
///
TemplateLibrary - custom control that holds a list of templates
///
This control provides a way to store an arbitrary list of templates
///
provided declaratively to it through mark-up. The templates are
///
made accessible through a property to any other object that needs them
///
</summary>
[
ParseChildren
(
true
,
"Templates"
),
PersistChildren
(
false
)]
public
class
TemplateLibrary
:
Control
{
public
TemplateLibrary()
{
_templates =
new
TemplateList
();
}
private
TemplateList
_templates;
[
PersistenceMode
(
PersistenceMode
.InnerProperty)]
public
TemplateList
Templates
{
get
{
return
_templates;
}
}
}
// The List<TemplateItems> so that a string indexer
// can also be used to reference items. (This isn't
// the most efficient running algorithm, but I don't
// expect a significantly large number of items to
// end up in the list and it is memory efficient.)
public
class
TemplateList
:
List
<
TemplateItem
>
{
public
TemplateItem
this
[
string
key]
{
get
{
foreach
(
TemplateItem
ti
in
this
)
{
if
(
string
.Compare(key, ti.Name,
StringComparison
.InvariantCultureIgnoreCase) == 0)
return
ti;
}
return
null
;
}
}
}
// Template object - contains a template and a name
public
class
TemplateItem
:
ITemplate
{
private
string
_name;
private
ITemplate
_template;
public
string
Name
{
get
{
return
_name; }
set
{ _name =
value
; }
}
// The Template
// Since it isn't "known" what the exact type of container
// will be used to instantiate a template, I just assume all
// of them will implement the IDataItemContainer interface,
// which is a good idea anyway for containers.
[
PersistenceMode
(
PersistenceMode
.InnerProperty),
TemplateContainer
(
typeof
(
IDataItemContainer
))]
public
ITemplate
Template
{
get
{
return
_template; }
set
{ _template =
value
; }
}
// This is just to help reduce one level of dereferencing
// needed to get a handle on the template object.
#region
ITemplate Members
public
void
InstantiateIn(
Control
container)
{
Template.InstantiateIn(container);
}
#endregion
}
}
Published
Jan 27 2006, 10:35 AM
by
dannychen
Filed under:
Code
Comments
No Comments
Leave a Comment
Name
(required)
Your URL
(optional)
Comments
(required)
Remember Me?
Add
Terms of Use