ITemplate.InstantiateIn Method (Control)


When implemented by a class, defines the Control object that child controls and templates belong to. These child controls are in turn defined within an inline template.

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

Sub InstantiateIn (
	container As Control


Type: System.Web.UI.Control

The Control object to contain the instances of controls from the inline template.

When developing templated server controls, you do not need to implement this method; the .NET Framework provides the implementation for you.

' Override the ITemplate.InstantiateIn method to ensure 
' that the templates are created in a Literal control and
' that the Literal object's DataBinding event is associated
' with the BindData method.
Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn
   Dim l As New Literal()
   AddHandler l.DataBinding, AddressOf Me.BindData
End Sub 'InstantiateIn

' Create a public method that will handle the
' DataBinding event called in the InstantiateIn method.
Public Sub BindData(sender As Object, e As EventArgs)
   Dim l As Literal = CType(sender, Literal)
   Dim container As DataGridItem = CType(l.NamingContainer, DataGridItem)
   l.Text = CType(container.DataItem, DataRowView)(column).ToString()
End Sub 'BindData 

.NET Framework
Available since 1.1
Return to top