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.
Assembly: System.Web (in System.Web.dll)
The following code example demonstrates a simple templated server control that uses the ITemplate interface to create a templated property.
using System; using System.Web; using System.Web.UI; namespace TemplateControlSamples { public class TemplateItem : Control, INamingContainer { private String _message = null; public TemplateItem(String message) { _message = message; } public String Message { get { return _message; } set { _message = value; } } } [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] [ParseChildren(true)] public class Template1 : Control, INamingContainer { private ITemplate _messageTemplate = null; private String _message = null; public String Message { get { return _message; } set { _message = value; } } [ PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(TemplateItem)) ] public ITemplate MessageTemplate { get { return _messageTemplate; } set { _messageTemplate = value; } } protected override void CreateChildControls() { // If a template has been specified, use it to create children. // Otherwise, create a single LiteralControl with the message value. if (MessageTemplate != null) { Controls.Clear(); TemplateItem i = new TemplateItem(this.Message); MessageTemplate.InstantiateIn(i); Controls.Add(i); } else { this.Controls.Add(new LiteralControl(this.Message)); } } } }
-
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.
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.
privateDataControlRowType templateType;
privatestring columnName;
privatestring dataType;
public Template1(DataControlRowType type,
string colname, string DataType)
{
templateType = type;
columnName = colname;
dataType = DataType;
}
and then you check it in your methods.
if (templateType == DataControlRowType.DataRow)
{
// ..
}
- 6/19/2009
- Okan Tekeli
- 6/19/2009
- Okan Tekeli
When I tried playing around further, I realized that <% %> tags wouldn't be processed within the ITemplate.
For example, I have a FormView in my page and I placed my WebControl within the FormView's ItemTemplate. Every <%# Eval() %> tag was processed nicely except for those within my WebControl's ITemplate.
My ITemplate is exactly like the codes above. Is there any extra codes I have to put in?
The code for my page is as follows:
<asp:FormView ID="FormView1" runat="server" DataSourceID="DS1">
<ItemTemplate><%# Eval("Field1") %>
<%= MyPageProperty %>
<wc1:MyControl ID="Control1" runat="server"><FirstTemplate></wc1:MyControl><%# Eval("Field1") %></FirstTemplate>
<%= MyPageProperty %>
</ItemTemplate></asp:FormView>
Any help is much appreciated. Thanks in advance! :D
- 3/26/2009
- yukscck