using System; using System.ComponentModel; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Collections.Generic; public class WebCartouche : CompositeControl { private Table _tablo; private TableCell _cellContent; private TableCell _cellTitle; protected override void CreateChildControls() { _tablo = new Table(); _cellTitle = new TableCell(); _cellContent = new TableCell(); TableRow tr1 = new TableRow(); TableRow tr2 = new TableRow(); tr1.Controls.Add(_cellTitle); tr2.Controls.Add(_cellContent); _tablo.Controls.Add(tr1); _tablo.Controls.Add(tr2); } protected override void Render(HtmlTextWriter output) { if (_tablo == null) CreateChildControls(); _tablo.RenderControl(output); } }
private ITemplate _contentTemplate; [Browsable(false), PersistenceMode(PersistenceMode.InnerProperty)] public ITemplate ContentTemplate { get { return _contentTemplate; } set { _contentTemplate = value; base.ChildControlsCreated = true; } } private ITemplate _titleTemplate; [Browsable(false), PersistenceMode(PersistenceMode.InnerProperty)] public ITemplate TitleTemplate { get { return _titleTemplate; } set { _titleTemplate = value; base.ChildControlsCreated = true; } }
protected override void CreateChildControls() { _tablo = new Table(); _cellTitle = new TableCell(); _cellContent = new TableCell(); TableRow tr1 = new TableRow(); TableRow tr2 = new TableRow(); if (_titleTemplate != null) { _titleTemplate.InstantiateIn(_cellTitle); } else if (this.DesignMode) { /* * En mode design, on affiche un texte par defaut pour avoir * une zone selectionnable. */ Literal l = new Literal(); l.Text = "Le titre"; _cellTitle.Controls.Add(l); } if (_contentTemplate != null) { _contentTemplate.InstantiateIn(_cellContent); } else if (this.DesignMode) { //on affiche par defaut pour avoir une zone selectionnable. Literal l = new Literal(); l.Text = "Mon contenu"; _cellContent.Controls.Add(l); } tr1.Controls.Add(_cellTitle); tr2.Controls.Add(_cellContent); _tablo.Controls.Add(tr1); _tablo.Controls.Add(tr2); }
internal List<IAttributeAccessor> regions;
regions = new List<IAttributeAccessor>(); regions.Add(_cellTitle); regions.Add(_cellContent);
[Designer(typeof(WebCartoucheDesigner))] [ToolboxData("<{0}:WebCartouche runat=server></{0}:WebCartouche>")] public class WebCartouche : CompositeControl