Implementing the ITemplate Interface

You create a one-way databinding template by adding a property to a control that returns an object that implements the ITemplate interface. The ITemplate interface includes one method:

InstantiateIn Instantiates the contents of a template in a particular control.

You are not required to implement the InstantiateIn() method. The ASP.NET Framework creates the method for you automatically. You call the InstantiateIn method in your control to add the contents of a template to your control.

For example, the control in Listing 37.1 represents an article. The Article control includes a template named ItemTemplate, which lays out the elements of the article: title, author, and contents.

Listing 37.1. Article.cs ...

Get ASP.NET 4 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.