VB.NET•Take a Look at VB.NET's Base Class Code

Listing 2. In the Page_Init event, you load the template control by using the LoadControl and Add methods.

Public Class PageBase : Inherits Page
   Private _title As New PlaceHolder
   Private Frame As Control
   Protected Header, Lefter, Body, Righter, _
      Footer As PlaceHolder

   Protected WriteOnly Property Title() As String
      Set(ByVal Value As String)
         _title.Controls.Clear()
         _title.Controls.Add(New _
            LiteralControl(Value))
      End Set
   End Property

Private Sub Page_Init(ByVal sender As Object, _
   ByVal e As EventArgs) Handles MyBase.Init
      Frame = LoadControl("ucMyTemp.ascx")
      Page.Controls.Add(Frame)

      _title = Frame.FindControl("_title")
      Header = Frame.FindControl("Header")
      Lefter = Frame.FindControl("Lefter")
      Body = Frame.FindControl("Body")
      Footer = Frame.FindControl("Footer")
      Righter = Frame.FindControl("Righter")
   End Sub

Private Sub Page_PreRender(ByVal sender As _
   Object, ByVal e As EventArgs) Handles _
   MyBase.PreRender
      If Header.Controls.Count = 0 Then
         Header.Controls.Add( _
            LoadControl("ucHeader.ascx"))
      End If

      If Lefter.Controls.Count = 0 Then
         Lefter.Controls.Add( _
            LoadControl("ucLefter.ascx"))
      End If

      If Righter.Controls.Count = 0 Then
         Righter.Controls.Add( _
            LoadControl("ucRighter.ascx"))
      End If

      If Footer.Controls.Count = 0 Then
         Footer.Controls.Add( _
            LoadControl("ucFooter.ascx"))
      End If
   End Sub
End Class