我的代碼(下)的工作原理除了將ref="abc"
添加到TemplateItem
標記時。當它包含我得到這個錯誤:無法將屬性添加到網絡用戶控件中的INamingContainer
Property 'TemplateItem' does not have a property named 'ref'
我該如何解決這個問題?
Default.aspx的
<%@ Register Src="~/message.ascx" TagName="Message" TagPrefix="uc" %>
<uc:Message ID="msg" runat="server" abc="123" >
<TemplateItem ref="abc">Hi</TemplateItem>
</uc:Message>
message.ascx
<asp:placeholder runat="server" id="PlaceHolder1" />
message.ascx.vb
Partial Class message
Inherits System.Web.UI.UserControl
Public Property abc() As String
Sub Page_Init()
If TemplateItem IsNot Nothing Then
TemplateItem.InstantiateIn(PlaceHolder1)
End If
End Sub
Private m_TemplateItem As ITemplate = Nothing
<TemplateContainer(GetType(TemplateItem2))> _
Public Property TemplateItem() As ITemplate
Get
Return m_TemplateItem
End Get
Set(ByVal value As ITemplate)
m_TemplateItem = value
End Set
End Property
Public Class TemplateItem2
Inherits Control
Implements INamingContainer
Public Property ref() As String
End Class
End Class