Пытаюсь создать простенький контрол с шаблоном. Вот серверный код:
Код | using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Security.Permissions; [ParseChildren(true)] public partial class Blog_BlogRecord : System.Web.UI.UserControl {
public ITemplate RecordTemplate { get { return _recordTemplate; } set { _recordTemplate = value; } } [PersistenceMode(PersistenceMode.InnerProperty)] [TemplateContainer(typeof(TemplateControl))]
protected void Page_Load(object sender, EventArgs e) { DataBind(); } protected override void OnInit(EventArgs e) { base.OnInit(e); RecordPH.Controls.Clear(); if (RecordTemplate == null) throw new Exception("Не указан шаблон."); RecordContainer container = new RecordContainer(); container.Test = "Test message"; RecordTemplate.InstantiateIn(container); RecordPH.Controls.Add(container); } } public class RecordContainer : Control, INamingContainer { public string Test; }
|
Но при попытки компиляции выдаёт такую ошибку:
Цитата | Attribute 'TemplateContainer' is not valid on this declaration type. It is only valid on 'property, indexer' declarations.
|
Решения я так и не нашёл, надеюсь на ваши ответы. Спасибо. |