私自身のサーバー コントロールでは、次のようなものを実装したいと思いますListView
。
<asp:ListView runat="server">
<LayoutTemplate>
<asp:PlaceHolder runat="server" id="itemPlaceholder" />
</LayoutTemplate>
</asp:ListView>
プロパティを作成しITemplate
ました。aspx ページでレイアウトを設定できますITemplate.InstantiateIn(myControl)
。
しかし、プレースホルダーにコントロールを挿入する方法がわかりません。のようなものになると思いMyTemplate.FindControl("itemPlaceholder").Controls.Add(myControl)
ます。my の型にキャストしようとしましたITemplate
が、エラーが発生しました:
Unable to cast object of type 'System.Web.UI.CompiledTemplateBuilder' to type 'MyNamespace.MyLayoutTemplate'
私は何が欠けていますか?
編集: http://www.nikhilk.net/SingleInstanceTemplates.aspx を見つけましたControl developers can define templates to be single instance using metadata which causes the ID'd controls within the template contents to be promoted to the page level... The parser and code-generator together work behind the scenes to add member fields, and initialize them at the right time.
。ユーザーコントロール専用のようですか?これを実行してから試しPage.FindControl()
ましたが、何も見つかりませんでした。