0
我正在構建自定義的asp.net服務器控件。它用於設計時間,但沒有顯示運行時間。我寫這個。在asp.net中沒有顯示自定義標籤
<cc1:TemplateMenu ID="TemplateMenu1" runat="server">
<HeaderTemplate>
<asp:Label ID="Title" Text="Hello World" runat="server"></asp:Label>
</HeaderTemplate>
<SperatorTemplate>|</SperatorTemplate>
<FooterTemplate>
<asp:TextBox ID="TextBox" Text="" runat="server"></asp:TextBox>
<asp:Button ID="Button" Text="Click Me" runat="server"/>
</FooterTemplate>
</cc1:TemplateMenu>
這是設計時間。
這是服務器控制代碼文件。
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Yoma.Yoma.CustomControls.BasicTemplate
Namespace Yoma.CustomControls.TemplateMenu
<DefaultProperty("Text"), ToolboxData("<{0}:TemplateMenu runat=server></{0}:TemplateMenu>")> _
Public Class TemplateMenu
Inherits CompositeControl
Private MenuData As New ArrayList
Public Sub New()
MenuData = New ArrayList
Dim MenuItem As New ListItem
MenuItem.Text = "Apress"
MenuItem.Value = "http://www.apress.com"
MenuData.Add(MenuItem)
MenuItem = New ListItem
MenuItem.Text = "Microsoft"
MenuItem.Value = "http://www.microsoft.com"
MenuData.Add(MenuItem)
MenuItem = New ListItem
MenuItem.Text = "ASP.Net"
MenuItem.Value = "http://asp.net"
MenuData.Add(MenuItem)
End Sub
#Region "HeaderTemplate"
Private _HeaderTemplate As ITemplate = Nothing
<Browsable(False), Description("The header template"), PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property HeaderTemplate() As ITemplate
Get
Return _HeaderTemplate
End Get
Set(ByVal value As ITemplate)
_HeaderTemplate = value
End Set
End Property
#End Region
#Region "FooterTemplate"
Private _FooterTemplate As ITemplate = Nothing
<Browsable(False), Description("The footer template"), PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property FooterTemplate() As ITemplate
Get
Return _FooterTemplate
End Get
Set(ByVal value As ITemplate)
_FooterTemplate = value
End Set
End Property
#End Region
#Region "SperatorTemplate"
Private _SperatorTemplate As ITemplate = Nothing
<Browsable(False), Description("The sperator template"), PersistenceMode(PersistenceMode.InnerProperty)> _
Public Property SperatorTemplate() As ITemplate
Get
Return _SperatorTemplate
End Get
Set(ByVal value As ITemplate)
_SperatorTemplate = value
End Set
End Property
#End Region
#Region "Create Control"
Public Sub CreateControlHierarchy()
If HeaderTemplate Is Nothing Then
Dim Header As New BasicTemplateContainer
HeaderTemplate.InstantiateIn(Header)
Controls.Add(Header)
End If
Dim Count As Integer = MenuData.Count
For Each Item As ListItem In MenuData
Dim Link As New HyperLink
Link.Text = Item.Text
Link.NavigateUrl = Item.Value
Controls.Add(Link)
Controls.Add(New LiteralControl("|"))
Next
If FooterTemplate Is Nothing Then
Dim Footer As New BasicTemplateContainer
FooterTemplate.InstantiateIn(Footer)
Controls.Add(Footer)
End If
End Sub
Protected Overrides Sub CreateChildControls()
Controls.Clear()
CreateControlHierarchy()
End Sub
Public Overrides ReadOnly Property Controls() As ControlCollection
Get
EnsureChildControls()
Return MyBase.Controls
End Get
End Property
Public Overrides Sub DataBind()
CreateChildControls()
ChildControlsCreated = True
MyBase.DataBind()
End Sub
#End Region
End Class
End Namespace
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Namespace Yoma.CustomControls.BasicTemplate
<DefaultProperty("Text"), ToolboxData("<{0}:BasicTemplateContainer runat=server></{0}:BasicTemplateContainer>")> _
Public Class BasicTemplateContainer
Inherits WebControl
Implements INamingContainer
Public Sub New()
Me.BorderWidth = 2
Me.BorderStyle = WebControls.BorderStyle.Outset
End Sub
End Class
End Namespace
請幫我...我真的有問題。
是的,我明白了,謝謝大家。但它到達了瀏覽器,它就像span標籤。我不喜歡這個。我糾正這一點。我可以?請告訴我。 – zanhtet 2010-12-14 07:14:47
@zanhtet,不確定你的意思是*像span標籤*!你能解釋一下嗎? – VinayC 2010-12-14 08:39:59