M
mnowosad
I created a custom composite control with contains a text box and a label. I
exposed the text box and label as properties of the custom control. As a
result, they are exposed correctly as expandable objects in the Properties
window, in design time.
I also have created the proper custom designer to generate the design time
HTML and this is working fine.
When I change a property value of the custom control (like Forecolor) using
the Properties window, the change is immediately reflected in the Designer
view and properly persisted in the HTML view, with the proper ASP.NET tags
(as it should be)
The problem is that when I change the values of the children controls, using
the Properties window, the changes are not reflected in the designer and not
persisted in the HTML view immediately. I have to change some other top-level
property of the custom control (like Forecolor again), to have the changes in
the children controls to be reflected in the designer and HTML view (with the
proper tags).
Any idea how to solve the problem?
I tried applying NotifyParentProperty to the properties that expose the
children controls, but it did not work. It seems tha changes in the children
controls properties are not broadcasted to the designer.
Here is a piece of the code:
[ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")]
[Designer(typeof(MyControlDesigner))]
public class MyControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private Label _label = new Label();
private TextBox _textBox = new TextBox();
[Category("Controls")]
[Description("My label.")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
public Label MyLabel
{
get
{
return _label;
}
}
[Category("Controls")]
[Description("My text box.")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
public Label MyTextBox
{
get
{
return _textBox;
}
}
}
exposed the text box and label as properties of the custom control. As a
result, they are exposed correctly as expandable objects in the Properties
window, in design time.
I also have created the proper custom designer to generate the design time
HTML and this is working fine.
When I change a property value of the custom control (like Forecolor) using
the Properties window, the change is immediately reflected in the Designer
view and properly persisted in the HTML view, with the proper ASP.NET tags
(as it should be)
The problem is that when I change the values of the children controls, using
the Properties window, the changes are not reflected in the designer and not
persisted in the HTML view immediately. I have to change some other top-level
property of the custom control (like Forecolor again), to have the changes in
the children controls to be reflected in the designer and HTML view (with the
proper tags).
Any idea how to solve the problem?
I tried applying NotifyParentProperty to the properties that expose the
children controls, but it did not work. It seems tha changes in the children
controls properties are not broadcasted to the designer.
Here is a piece of the code:
[ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")]
[Designer(typeof(MyControlDesigner))]
public class MyControl : System.Web.UI.WebControls.WebControl,
INamingContainer
{
private Label _label = new Label();
private TextBox _textBox = new TextBox();
[Category("Controls")]
[Description("My label.")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
public Label MyLabel
{
get
{
return _label;
}
}
[Category("Controls")]
[Description("My text box.")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
public Label MyTextBox
{
get
{
return _textBox;
}
}
}