. NET Framework Supplements (4) Itemplater,templatecontainerattribute__.net

Source: Internet
Author: User

. NET Framework Supplements (4) Itemplater,templatecontainerattribute

Directory:
1.Itemplater interface
2.ItemplateContainerAttribute class

1.Itemplate interface

When declared in an. aspx file, populates the ASP.net server control with child controls when using controls with inline templates to define the method to implement.

Public Interface ITemplate

This interface is intended for use by custom server controls, but is never implemented through these server controls, and ASP.net is always responsible for implementing the interface.

Members have only one public method
Sub InstantiateIn (ByVal Container As Control)
Container: Control object containing instantiated controls in inline templates
You do not need to implement this method when developing a template server control.

Public Sub InstantiateIn (container as control) Implements Itemplate.instantiatein
Dim L as New Literal ()
AddHandler l.databinding, AddressOf me.binddata
Container. Controls.Add (L)
End Sub ' InstantiateIn


'------------------------------------------------------------------------------------------------

2.ItemplateContainerAttribute class

Declares the type of INamingContainer that will contain the template after it is created.
System.Object
System.Attribute
System.Web.UI.TemplateContainerAttribute

<attributeusage (Attributetargets.property) >
NotInheritable Public Class TemplateContainerAttribute
Inherits Attribute


'**********************************************************************************************

' File Name:templatecontainerattribute.cs.

Imports System
Imports system.web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Collections


Namespace CustomControls
<parsechildren (True) > _
Public Class Vb_templatedfirstcontrol
Inherits Control
Implements INamingContainer

Private _firsttemplate as ITemplate
Private [_text] as [String] = Nothing
Private _mytemplatecontainer as Control

<system.security.permissions.permissionsetattribute (System.Security.Permissions.SecurityAction.Demand, Name: = "FullTrust") > _
Protected Overrides Sub ondatabinding (e as EventArgs)
EnsureChildControls ()
Mybase.ondatabinding (e)
End Sub


Public Property FirstTemplate () as ITemplate
Get
Return _firsttemplate
End Get

Set
_firsttemplate = value
End Set
End Property

Public Property [Text] () as [String]
Get
return [_text]
End Get

Set
[_text] = value
End Set
End Property

Public ReadOnly Property DateTime () as [String]
Get
Return System.DateTime.Now.ToLongTimeString ()
End Get
End Property

Public ReadOnly Property Mytemplatecontainer () as Control
Get
Return _mytemplatecontainer
End Get
End Property

<system.security.permissions.permissionsetattribute (System.Security.Permissions.SecurityAction.Demand, Name: = "FullTrust") > _
Protected Overrides Sub CreateChildControls ()

If not (FirstTemplate are nothing) Then
_mytemplatecontainer = New Vb_firsttemplatecontainer (Me)
Firsttemplate.instantiatein (_mytemplatecontainer)
Controls.Add (_mytemplatecontainer)
Else
Controls.Add (New LiteralControl ([Text] + "" + DateTime)
End If
End Sub ' CreateChildControls

  End Class ' Vb_templatedfirstcontrol
 
  
  public Class vb_ Firsttemplatecontainer
    Inherits control
    Implements INamingContainer

Private _parent as Vb_templatedfirstcontrol

Public Sub New (parent as Vb_templatedfirstcontrol)
Me._parent = Parent
End Sub ' New

Public ReadOnly Property [Text] () as [String]
Get
Return _parent. Text
End Get
End Property

Public ReadOnly Property DateTime () as [String]
Get
Return _parent. Datetime
End Get
End Property

End Class ' Vb_firsttemplatecontainer

End Namespace ' CustomControls

'***********************************************************************************


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.