TemplateControl Class
Provides the Page class and the UserControl class with a base set of functionality.
Assembly: System.Web (in System.Web.dll)
'Declaration <AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ <AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _ Public MustInherit Class TemplateControl _ Inherits Control _ Implements INamingContainer, IFilterResolutionService 'Usage Dim instance As TemplateControl
<asp:TemplateControl />
The TemplateControl class is an abstract class that provides common properties and methods for the Page class and the UserControl class. A new instance of the TemplateControl is not created directly.
The TemplateControl class defines methods supporting declarative data-binding expressions:
Use the Eval method for data-binding expression involving data sources, such as simple properties or expressions.
Use the XPath method for parsing and evaluating an XPath data-binding expression.
Use the XPathSelect method for data-binding against an expression containing an XPath select statement. The result is a node collection that implements the IEnumerable interface.
For more information on data-binding expression, see Data-Binding Expression Syntax and Binding to Databases.
The following code example demonstrates how to derive a control named MyControl from the TemplateControl class and override the Construct method. When MyControl is initialized, the overridden Construct method is called.
Imports System Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Security.Permissions ' The custom user control class. <AspNetHostingPermission(SecurityAction.Demand, _ Level:=AspNetHostingPermissionLevel.Minimal)> _ Public Class MyControl Inherits UserControl ' Create a Message property and accessors. Private _message As String = Nothing Public Property Message() As String Get Return _message End Get Set _message = value End Set End Property ' Create an event for this user control Public Event myControl As System.EventHandler ' Override the default constructor. Protected Overrides Sub Construct() ' Specify the handler for the OnInit method. AddHandler Me.myControl, AddressOf MyInit End Sub Protected Overrides Sub OnInit(ByVal e As EventArgs) RaiseEvent myControl(Me, e) Response.Write("The OnInit() method is used to raise the Init event.") End Sub ' Use the MyInit handler to set the Message property Sub MyInit(ByVal sender As Object, ByVal e As System.EventArgs) Message = "Hello World!" End Sub ' Render the value of the Message property Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) writer.Write(("<br>Message :" & Message)) End Sub End Class
- AspNetHostingPermission
for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
- AspNetHostingPermission
for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.
System.Web.UI.Control
System.Web.UI.TemplateControl
System.Web.UI.Page
System.Web.UI.UserControl
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.