Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Building Controls / August 2006

Tip: Looking for answers? Try searching our database.

Dirty property value persist problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yp.yean@gmail.com - 24 Aug 2006 05:20 GMT
Hi,

I created a custom control, and encountered a dirty property value
persistence problem.
I created a property with a custom class type, call SQLSettings which
holds the SQL connection parameters, the class as follows:

public sealed class SQLSettings
{
       private string serverName;
       .......

       public SQLSettings()
       {
           this.serverName = string.Empty;
           ......
       }

       [NotifyParentProperty(true)]
       public string ServerName
       {
           get
           {
               return this.serverName;
           }
           set
           {
               this.serverName = value;
           }
       }
..................

And, I also created an mapping TypeConverter and UITypeEditor classes
to handle the design-time founctinality. The property I created in my
conbtrol as follows:

           [BrowsableAttribute(true)]
           [CategoryAttribute("Behavior")]
           [BindableAttribute(true)]
           [NotifyParentProperty(true)]
           [EditorAttribute(typeof(SQLSettingsUITypeEditor),
typeof(UITypeEditor))]

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

           [TypeConverter((Type)typeof(SQLSettingsTypeConverter))]
           [PersistenceModeAttribute(PersistenceMode.InnerProperty)]
           public SQLSettings SQLSettingsData
           {
               get
               {
                   return this._sqlSettings;
               }
               set
               {
                   this._sqlSettings = value;
               }
           }

They all works fine when first set value to this property, I can see
the persisted data showed in .aspx file. When I go back to design view
and update the property value via my UITypeEditor, I can see the value
already updated in VS.NET properties browser. But when I turn to see
.aspx file in code view, I didn't see the dirty property value updated
in .aspx file. When I turn to design view, the updated property value
is lost, it remain keep the first persisted value.

How to solve this problem? Any idea?
Thank you for your kindly help.
Teemu Keiski - 25 Aug 2006 21:50 GMT
As it's complex type, property should be read-only

...
public SQLSettings SQLSettingsData
       {
           get
           {
               if (this._sqlSettings == null)
                   this._sqlSettings = new SQLSettings();
               return this._sqlSettings;
           }

       }

Signature

Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

> Hi,
>
[quoted text clipped - 65 lines]
> How to solve this problem? Any idea?
> Thank you for your kindly help.
yp.yean@gmail.com - 26 Aug 2006 02:17 GMT
Dear Teemu,

Thank you for your kindly relply. But if the complex type property need
to be read-only, how can I set the value to it through my UITypeEditor?
Is there any solution? Thank you.

Daniel

Teemu Keiski 寫道:

> As it's complex type, property should be read-only
>
[quoted text clipped - 85 lines]
> > How to solve this problem? Any idea?
> > Thank you for your kindly help.
Teemu Keiski - 26 Aug 2006 08:42 GMT
Note that read-only means that you don't set the reference, you set directly
its properties.means that in your editor, you don't instantiate new
SqlSettings, but rather set the properties of the instance returned to you
by the control. Though this also more from page parsing point of view,
generic rule is that complex types must be read-only because page parsing
won't set the instance.

Signature

Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Dear Teemu,

Thank you for your kindly relply. But if the complex type property need
to be read-only, how can I set the value to it through my UITypeEditor?
Is there any solution? Thank you.

Daniel

Teemu Keiski ??:

> As it's complex type, property should be read-only
>
[quoted text clipped - 87 lines]
> > How to solve this problem? Any idea?
> > Thank you for your kindly help.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.