1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design;
using System.ComponentModel;
namespace Artisteer
{
[ParseChildren(true)]
[Designer(typeof(ArticleDesigner))]
public class Article : WebControl
{
private ITemplate _contentTemplate = null;
private PlaceHolder _headerPlaceholder = null;
private PlaceHolder _contentPlaceholder = null;
private string _caption;
public string Caption
{
get { return _caption; }
set { _caption = value; }
}
[Browsable(false)]
[TemplateContainer(typeof(TemplateContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ITemplate ContentTemplate
{
get { return _contentTemplate; }
set { _contentTemplate = value; }
}
public PlaceHolder HeaderPlaceholder
{
get { return _headerPlaceholder; }
set { _headerPlaceholder = value; }
}
public PlaceHolder ContentPlaceholder
{
get { return _contentPlaceholder; }
set { _contentPlaceholder = value; }
}
protected override void CreateChildControls()
{
Controls.Clear();
Control articleMarkup = Page.LoadControl("~/Design/Article.ascx");
_headerPlaceholder = articleMarkup.FindControl("HeaderPlaceholder") as PlaceHolder;
_contentPlaceholder = articleMarkup.FindControl("ContentPlaceholder") as PlaceHolder;
_headerPlaceholder.Visible = ! String.IsNullOrEmpty(_caption);
if (_headerPlaceholder.Visible)
{
Literal caption = new Literal();
caption.Text = _caption;
_headerPlaceholder.Controls.Add(caption);
}
if (_contentTemplate != null)
{
TemplateContainer container = new TemplateContainer();
_contentTemplate.InstantiateIn(container);
_contentPlaceholder.Controls.Add(container);
}
Controls.Add(articleMarkup);
}
public override void DataBind()
{
EnsureChildControls();
base.DataBind();
}
protected override HtmlTextWriterTag TagKey
{
get { return HtmlTextWriterTag.Div; }
}
public class TemplateContainer : Control, INamingContainer
{
}
}
public class ArticleDesigner : ContainerControlDesigner
{
public override string FrameCaption
{
get
{
Article ctl = this.Component as Article;
return ctl.Caption;
}
}
}
} |
Partager