Asp.net: Lack of the NotifyParentProperty on TextBox's properties

by brunofig 2. February 2007 02:07
 

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

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.7
Theme by Mads Kristensen

About the author

Hi!

My name is Bruno and I'am a senior consultant. When I'm not working, you can catch me playing with my daugther, taking photos and hanging out with my wife and friends. :)

You can also check my dark side or have fun with my vision of the world.

View Bruno Figueiredo's profile on LinkedIn

TwitterCounter for @brunoshine
 
Creative Commons License

 
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
 

Ads

    Page List

      Most comments

      Busby SEO Test Busby SEO Test
      2 comments
      kh Cambodia
      laptop cases laptop cases
      2 comments
      Busby SEO Test Busby SEO Test
      1 comments

      RecentComments

      Comment RSS

      Popuri.us

      My Popularity (by popuri.us)