Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Разработка под ASP.NET > Атрибут TemplateControl


Автор: POLTER 8.11.2008, 22:51
Пытаюсь создать простенький контрол с шаблоном.
Вот серверный код:
Код

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.

Решения я так и не нашёл, надеюсь на ваши ответы.
Спасибо.

Автор: POLTER 8.11.2008, 23:18
Чёрт.. Что-то я не заметил, что поставил атрибуты после метода а не перед..
Тему можно закрывать.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)