W
Wayne Brantley
Hi,
Create a simple composite control using ASP2.0 CompositeControl class.
Have two webcontrols exposed as properties, so they show as subproperties in
at designtime in the properties window.
Change any of the these webcontrol properties - switch to source view -
none of the properties are persisted.
Now, switch back to design mode, change a property of them main
CompositeControl - change anything, set width to 1px and then set it back to
blank. Now, go directly and change those same webcontrol properties you
just tried. Switch to source view - all the properties persisted!
Here is a simple webcontrol that demonstrates this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Sample.WebControls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:TestCC1 runat=server></{0}:TestCC1>")]
public class TestCC1 : CompositeControl
{
public TestCC1()
{
this.EnsureChildControls();
}
private TextBox textBox;
private Label label;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[NotifyParentProperty(true)]
public TextBox EditBox
{
get
{
if (this.textBox == null)
this.textBox=new TextBox();
return this.textBox;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[NotifyParentProperty(true)]
public Label TextLabel
{
get
{
if (this.label == null)
this.label = new Label();
return this.label;
}
}
protected override void CreateChildControls()
{
this.Controls.Add(EditBox);
this.Controls.Add(TextLabel);
base.CreateChildControls();
}
}
}
Wayne Brantley
Create a simple composite control using ASP2.0 CompositeControl class.
Have two webcontrols exposed as properties, so they show as subproperties in
at designtime in the properties window.
Change any of the these webcontrol properties - switch to source view -
none of the properties are persisted.
Now, switch back to design mode, change a property of them main
CompositeControl - change anything, set width to 1px and then set it back to
blank. Now, go directly and change those same webcontrol properties you
just tried. Switch to source view - all the properties persisted!
Here is a simple webcontrol that demonstrates this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Sample.WebControls
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:TestCC1 runat=server></{0}:TestCC1>")]
public class TestCC1 : CompositeControl
{
public TestCC1()
{
this.EnsureChildControls();
}
private TextBox textBox;
private Label label;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[NotifyParentProperty(true)]
public TextBox EditBox
{
get
{
if (this.textBox == null)
this.textBox=new TextBox();
return this.textBox;
}
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[NotifyParentProperty(true)]
public Label TextLabel
{
get
{
if (this.label == null)
this.label = new Label();
return this.label;
}
}
protected override void CreateChildControls()
{
this.Controls.Add(EditBox);
this.Controls.Add(TextLabel);
base.CreateChildControls();
}
}
}
Wayne Brantley