我希望我的用户控件能够在其中包含文字内容。例如:
<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'.
此控件可能包含除文本以外的其他内容,因此将内容属性设置为属性不会解决我的问题。
我在一些地方发现我需要实现ControlBuilder类,以及另一个实现IParserAccessor的类。
无论如何,我只希望我的默认“content”属性中允许所有类型的控件,包括文本控件和实际控件。