- Posted by brunofig on February 1, 2007
It seems that the TextBox's properties are not marked with the NotifyParentProperty attribute.
"What is the NotifyParentProperty attribute?"
The MSDN definition states that the NotifyParentProperty "indicates that the parent property is notified when the value of the property that this attribute is applied to is modified."
"Apply NotifyParentPropertyAttribute to a property if its parent property should receive notification of changes to the property's values. For example, the Size property has two nested properties: height and width. These nested properties should be marked with NotifyParentPropertyAttribute(true) so they notify the parent property to update its value and display when the property values change."
"So what?"
What happens is that when developing custom controls that expose the TextBox as a property, the design-mode isn't notified of the changes made to the property, thus, not reflection this changes to the html source.
For controls developers this is "hell".
"Now what?"
What happens now? well it seems that we have two solutions:
1. We can mark the property as browsable(false),set the DesignerSerializationVisibility to content and PersistenceMode to innerProperty. Any other property can be set on the source-mode, because the builder will parse the composite inner content and reflect it to its own properties:
<flv:SimpleComposite ID="TextBox1" runat="server">
<TextBox CssClass="DemoCss"></TextBox>
</flv:SimpleComposite>
Or
2. We can create a custom TextBox that overrides all the base TextBox properties and mark them as NotifyParentProperty, and expose this new TextBox as the composite property.
From the above solutions the first seems the better, because it allows the design-time support for the composite and the intellisense for the TextBox.
It would be nice that in Orcas this problem was solved.
NOTE: This is also a problem for the remaining controls, such as the dropdownlist.
Composite Control Code:
using System.ComponentModel;using System.Web.UI;using System.Web.UI.WebControls;namespace DoomsDay.Web.UI.WebControls{ public class SimpleComposite:CompositeControl { private System.Web.UI.WebControls.TextBox _txt = new TextBox(); [NotifyParentProperty(true), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerProperty)] public System.Web.UI.WebControls.TextBox TextBox { get { return _txt; } set { _txt = value; } } protected override void CreateChildControls() { base.CreateChildControls(); this.TextBox.ID = "TextBox"; this.Controls.Add(TextBox); } }}