<%@ Page Language="VB" %>
<%@ Register Assembly="WebControlLibrary1" Namespace="WebControlLibrary1"
TagPrefix="cc1" %>
Templated Web Controls
File: TemplatedControl.vb
Imports System.ComponentModel
Imports System.Web.UI
Imports System.Web.UI.WebControls
_
{0}:TemplatedControl>")> _
Public Class TemplatedControl
Inherits System.Web.UI.WebControls.WebControl
Private _name As String
Private _text As String
Private _message As Message
Private _messageTemplate As ITemplate
Public ReadOnly Property Message() As Message
Get
EnsureChildControls()
Return _message
End Get
End Property
TemplateContainer(GetType(Message))> _
Public Property MessageTemplate() As ITemplate
Get
Return _messageTemplate
End Get
Set(ByVal value As ITemplate)
_messageTemplate = value
End Set
End Property
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property Text() As String
Get
Return _text
End Get
Set(ByVal value As String)
_text = value
End Set
End Property
Public Overrides Sub DataBind()
CreateChildControls()
ChildControlsCreated = True
MyBase.DataBind()
End Sub
Protected Overrides Sub CreateChildControls()
Me.Controls.Clear()
_message = New Message(Name, Text)
Dim template As ITemplate = MessageTemplate
template.InstantiateIn(_message)
Controls.Add(_message)
End Sub
End Class