Changes in controls exposed as properties not reflected in design

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;
}
}
}
 
J

Jason Bentley

Mnowosad, it is my understanding that when you expose controls as
properties, you will have to override each and every property of the
child control and add the NotifyParentProperty attribute to each
control property. Yeah, have fun.

Jason Bentley
http://geekswithblogs.net/jbentley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top