1
我希望我的用户控件能够在其中包含文字内容。例如:ASP.NET自定义控件 - 允许文字内容的模板
<fc:Text runat="server">Please enter your login information:</fc:Text>
目前为我的用户控件的代码是:
<ParseChildren(True, "Content")> _
Partial Public Class ctrFormText
Inherits UserControl
Private _content As ArrayList
<PersistenceMode(PersistenceMode.InnerDefaultProperty), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
TemplateInstance(TemplateInstance.Single)> _
Public Property Content() As ArrayList
Get
If _content Is Nothing Then
Return New ArrayList
End If
Return _content
End Get
Set(ByVal value As ArrayList)
_content = value
End Set
End Property
Protected Overrides Sub CreateChildControls()
If _content IsNot Nothing Then
ctrChildren.Controls.Clear()
For Each i As Control In _content
ctrChildren.Controls.Add(i)
Next
End If
MyBase.CreateChildControls()
End Sub
End Class
当我把文本此控件(如上面)我得到这个错误:
Parser Error Message: Literal content ('Please enter your login information to access CKMS:') is not allowed within a 'System.Collections.ArrayList'.
此控件可能包含其他内容而不仅仅是文本,因此将Content属性设置为属性不会解决我的问题。
我发现在一些地方,我需要实现一个ControlBuilder类,以及另一个类实现IParserAccessor。
无论如何,我只是希望我的默认“内容”属性具有允许在其中的所有类型的控件,包括文字和实际控件。