November Happy Hour will be moved to Thursday December 5th.

Start page properties values are not updated on child pages

Vote:
 

Hi All,I am resusing some of my property values from start page into my other pages as reusable component.  

But when I update the value on start page its not updated on other pages .It still has the old value. Do anyone faced this issue before , some kind of caching?

#143255
Jan 18, 2016 16:35
Vote:
 

Can you give sample code of such property which reuses Start page properties?

#143256
Jan 18, 2016 16:56
Vote:
 

Here is an example :-

If childpage property is not set I set the StartPage Property..

ChildPage.Property = ChildPage.Property == null ?  StartPage.PropertyName :ChildPage.Property

#143257
Jan 18, 2016 17:52
Vote:
 

And where do you run this code? In some event, controller's action or in Property's getter?

#143259
Jan 18, 2016 17:54
Vote:
 

I override the Below Method:-

The code gets the startpage property value but after I update the update is not reflected in the property.

public override void SetDefaultValues(ContentType contentType)
{

base.SetDefaultValues(contentType);
LanguageHeading = !string.IsNullOrEmpty(startPage.Property["LanguageHeading"].ToString()) ? startPage.Property["LanguageHeading"].ToString() : string.Empty;
}

#143262
Jan 18, 2016 18:17
Vote:
 

SetDefaultValues is called only once when the page (or other IContent) is created. It is not called when you save the page later.

Instead I suggest you to handle this in the property itself:

public class MyPage : PageData
{

	public string DefaultHeading = "My heading";

	[Display(Order = 20)]
	[CultureSpecific]
	public virtual string LanguageHeading
	{
		get
		{
			return this.GetPropertyValue(p => p.LanguageHeading) ?? DefaultHeading;
		}
		set
		{
			this.SetPropertyValue(p => p.LanguageHeading, value);
		}
	}
}
#143263
Jan 18, 2016 18:29
Vote:
 

Is startPage or StartPage a static variable or property? If so, that's probably the problem. You need to fetch the startpage every time, which is not a problem since it's cached.

#143269
Jan 18, 2016 20:42
Vote:
 

Thanks Johan and Maris for the answers.

@Maris 

Since client has created many subsites (close to 40)  all the default values has been set on live , i.e. value from start page while creating the page during override of SetDefaultValues() method .

So properties will never be null or empty now . My requirement was  IF property is not set in Subsite for that page it should get from Startpage of the page.  Since now all the properties has some value how do I change the logic now ??

@Johan 

Yes I had made static property ,now I changed that . Thanks for pointing it . 

#143313
Jan 20, 2016 6:58
Vote:
 

Now you can create ScheduledJob which goes through all pages and resets that property to null if it equals to start page property's value. It might look something like this in the ScheduledJob's Execute method:

var allPages = GetAllSitePages();

foreach(var page in allPages)
{
    if(page.MyProperty == startPage.MyProperty)
    {
        page.MyProperty = null;
        _contentRepository.Save(page);
    }
}
#143323
Edited, Jan 20, 2016 11:20
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.