以下のサンプルマークアップに従って、ページ上にさまざまなTextBoxまたはDropDownList要素を含むフィルターバーを作成しようとするユーザーコントロールを設計しています。
<gf:GridFilterBar runat="server">
<filters>
<filter Label="Field1" Type="TextBox" />
<filter Label="Field2" Type="DropDownList" />
</filters>
</gf:GridFilterBar>
別の投稿からのインスピレーションを使用して、このマークアップを適切に解析し、目的の各子コントロールのプロパティを読み取るコードを作成しました。私が抱えている問題は、この情報を実際に画面に表示するときです。「Filter」クラスの「New」サブ内から初期化したすべてのコントロールが画面に表示されることはありません。「New」サブにブレークポイントを設定し、何が起こっているかを追跡すると、Filter.Newサブが2回トラバースされ、値が読み込まれていることがわかりますが、そのサブ内から初期化したものはページに影響を与えません。私の知る限りでは、すべて正常に作成されています。これは、Labelプロパティのみが読み取られているコードのサンプルです。
Imports System
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Public Class GridFilterBar
Inherits System.Web.UI.UserControl
Private _Filters As New FiltersClass(Me)
<PersistenceMode(PersistenceMode.InnerProperty)> _
Public ReadOnly Property Filters() As FiltersClass
Get
Return _Filters
End Get
End Property
Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
DDL.Visible = True
End Sub
End Class
Public Class FiltersClass
Inherits ControlCollection
Public Sub New(ByVal owner As Control)
MyBase.New(owner)
End Sub
Public Overrides Sub Add(ByVal child As System.Web.UI.Control)
MyBase.Add(New Filter(child))
End Sub
End Class
Public Class Filter
Inherits HtmlGenericControl
Public Sub New(ByVal GenericControl As HtmlGenericControl)
Label = GenericControl.Attributes("Label")
Dim lit As New Literal
lit.Text = Label.ToString
Me.Controls.Add(lit)
End Sub
Public Property Label As String = String.Empty
Public Overrides Function ToString() As String
Return Me.Label
End Function
End Class
誰かが私が間違っていることを見つけることができますか?