Export (0) Print
Expand All

ITemplate Interface

Defines the behavior for populating a templated ASP.NET server control with child controls. The child controls represent the inline templates defined on the page.

Namespace:  System.Web.UI
Assembly:  System.Web (in System.Web.dll)

public interface ITemplate

This interface is used by custom server controls, but never implemented by them. ASP.NET always implements it.

The following code example demonstrates a simple templated server control that uses the ITemplate interface to create a templated property.

import System
import System.Web
import System.Web.UI

package TemplateControlSamplesJS{

    class TemplateItem extends Control implements INamingContainer{

        private var message : String = null

        function TemplateItem(message : String){
            this.message = message
        }

        function get Message() : String{
           return message
        }

        function set Message(value : String){
           message = value
        }
    }

    public ParseChildren(true)
    class Template1JS extends Control implements INamingContainer{

        private var messageTemplate : ITemplate = null
        private var message : String = null

        function get Message(): String{
           return message
        }

        function set Message(value : String){
           message = value
        }

        public TemplateContainer(TemplateItem)
        function get MessageTemplate() : ITemplate{
           return messageTemplate
        }

        function set MessageTemplate(value : ITemplate){
           messageTemplate = value
        }

        protected function CreateChildControls(){

           // if(a template has been specified, use it to create children.
           // Otherwise, create a single literalcontrol with message value

           if(MessageTemplate != null){
              Controls.Clear()
              var I : TemplateItem = new TemplateItem(this.Message)
              MessageTemplate.InstantiateIn(I)
              Controls.Add(I)
           }else
              this.Controls.Add(new LiteralControl(this.Message))
        }

    }

}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft