Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Make a page property ReadOnly dynamically based on some condition.


I have a string type PageProperty. I have not make it ReadOnly. I am setting default value for this property in the SetDefaultValue method. After setting it to a default value, I need to make it ReadOnly based on a condition. I have written following code snippet in SetDefaultValue method to try making it readonly.

                this.SampleProperty= "Lorem Ipsum";

                PropertyDescriptor descriptor = TypeDescriptor.GetProperties(GetType())["SampleProperty"];

                ReadOnlyAttribute attrib = (ReadOnlyAttribute)descriptor.Attributes[typeof(ReadOnlyAttribute)];

                FieldInfo isReadOnly = attrib.GetType().GetField("isReadOnly", BindingFlags.NonPublic | BindingFlags.Instance);


But it is shwing error "lazy load property value is not supported by the current property instance" in the console.

Any ideas about how can we make it happen?


Edited, Sep 28, 2017 15:06

What is the requirement? You don't want certain admins to change the value?

Maybe you can create a custom validation attribute instead?

Sep 28, 2017 16:06

Hi Johan,

Thanks for replying.

Our requirement is 

  1. We need to set default value for that page property.
  2. After setting it to default value and checking a condition that current Page's parent is a particular page say "ParentPage", we need to make it ReadOnly. If current Page's parent is not "ParentPage", we need to keep it as it is.

Note: We are not making that property ReadOnly explicitly. 


Sep 28, 2017 16:18

In that case I would either create a custom validation attribute or custom validator, please see

If you go with a custom validator, IValidate<T>, you have easy access to the content and can check its parents. This will not make the property editor read-only though, but it will stop admins from changing the value. You can also extended with a custom editor (dojo/dijit) that makes the editor read-only as well, but that seems a bit overkill.

I would not recommend putting this logic inside the content model itself.

Sep 28, 2017 16:27


It should be possible to modify the metadata to make the property show up as read only as well.

Either you can implement an IMetadataExtender and put the logic there, like this pattern:

Or you can add an EditorDescriptor and decorate your property with a UiHint that you also set on the desciptor. Here is an example of that (except for the UiHint part:


Per Gunsarfs

Sep 28, 2017 16:42


I posted about using a IMetadataExtender here:

You can use the same approach to set the ReadOnly on the property based on the parent.


Sep 28, 2017 21:37
<div class="blockQuote"> <div class="borderBottom"><a href="">David Knipe said:</a></div> <p>Hi</p> <p>I posted about using a IMetadataExtender here:&nbsp;<a href=""></a></p> <p>You can use the same approach to set the ReadOnly on the property based on the parent.</p> <p>David</p> </div> <p>Thanks David.</p> <p>It worked like charm.</p>
Sep 29, 2017 7:56
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.