【发布时间】:2010-06-25 13:01:57
【问题描述】:
我有 2 个用户控件,我被用作另一个的容器:
<mc:Container runat="server" ID="container">
<mc:MyControl runat="server" ID="test">
</mc:Container>
mc 容器有一个名为 content 的默认内部属性,它是 MyControls 的集合。
上面的标记在FormView 内,当我在formview 上调用FindControl 时,它可以找到容器,但找不到测试。
如何让容器控件不创建新的命名容器?
编辑__
当不在FormView 中时,内部控件的 ID 会在设计器中显示为页面的一部分,因此它可以正常工作。
编辑__
这是我的容器vb:
<ParseChildren(True, "Content")> _
Partial Public Class ctrFormContainer
Inherits System.Web.UI.UserControl
Private _content As FormControlCollection
<PersistenceMode(PersistenceMode.InnerDefaultProperty), _
TemplateInstance(TemplateInstance.Single)> _
Public Property Content() As FormControlCollection
Get
Return _content
End Get
Set(ByVal value As FormControlCollection)
_content = value
End Set
End Property
Protected Overrides Sub CreateChildControls()
If _content IsNot Nothing Then
ctrChildren.Controls.Clear()
For Each i As FormControl In _content
ctrChildren.Controls.Add(i)
Next
End If
MyBase.CreateChildControls()
End Sub
Public Overrides Function FindControl(ByVal id As String) As System.Web.UI.Control
Return MyBase.FindControl(id)
End Function
Public Class FormControlCollection
Inherits List(Of FormControl)
End Class
End Class
【问题讨论】:
标签: asp.net user-controls