Try our conversational search powered by Generative AI!

Ruslan Minasian
Nov 4, 2010
  3628
(0 votes)

Custom Property Type and SaveData Method

In out project we use PropertyPageReferenceCollection to store references to local pages. It has PageReferenceCollection under the hood and calls its Parse and ToString methods to load and save the data. Evetything was fine until we decided to make some property (let’s call it Links) of this type required. The application started to crash while loading the page with empty Links property.

I’ve spend a lot of time looking how to prevent LoadData from crash while the error was in SaveData method. When LocalPageProvider loads a page it goes through all the properties from DB calls PropertyData.LoadData method for each property which value is not DBNull.Value. Since our SaveData implementation used PageReferenceCollection.ToString it returned string.Empty for empty collection and that value was stored in the DB. Then, after we set Links property as required, LoadData started to crash since string.Empty caused PropertyData.Clear to be called for required property.

Moral: always implement SaveData property so it returns null if PropertyData.IsNull is true.

Nov 04, 2010

Comments

Please login to comment.
Latest blogs
From Procrastination to Proficiency: Navigating Your Journey to Web Experimentation Certification

Hey there, Optimizely enthusiasts!   Join me in celebrating a milestone – I'm officially a certified web experimentation expert! It's an exhilarati...

Silvio Pacitto | May 17, 2024

GPT-4o Now Available for Optimizely via the AI-Assistant plugin!

I am excited to announce that GPT-4o is now available for Optimizely users through the Epicweb AI-Assistant integration. This means you can leverag...

Luc Gosso (MVP) | May 17, 2024 | Syndicated blog

The downside of being too fast

Today when I was tracking down some changes, I came across this commit comment Who wrote this? Me, almost 5 years ago. I did have a chuckle in my...

Quan Mai | May 17, 2024 | Syndicated blog

Optimizely Forms: Safeguarding Your Data

With the rise of cyber threats and privacy concerns, safeguarding sensitive information has become a top priority for businesses across all...

K Khan | May 16, 2024