Reputation: 103
I need to add a validator condition in a composer block (class) in Episerver, so I started from this:
[PageType("110187CD-89F0-40A8-A075-68944DD5AC1D",
Name = "New Composer Block",
Description = "My Description",
Filename = "/Templates/Webform1.aspx")]
public class ComposerPage : ComposerPageBase
{
[PageTypeProperty(
DisplayInEditMode = false,
UniqueValuePerLanguage = false,
Type = typeof(LongString),
Tab = typeof(ComposerTab))]
public virtual string MainArea { get; set; }
}
and rewrote the accessor (getter and setter) part as: .....
public virtual string MainArea
{
get { return this.GetPropertyValue(p => p.MainArea); }
set {
if(conditionhere)
this.SetPropertyValue(p => p.MainArea, "abc");
else this.SetPropertyValue(p => p.MainArea, value);
}
}
However, editing the page does not take into account my custom setter (it behaves as though I had a regular {get; set;} and moreover, the breakpoint on the setter can't be reached during debug! (quite unexpected and seems to relate to the inner workings on episerver/PTB).
So interested in:
Upvotes: 0
Views: 68
Reputation: 7391
With PageTypeBuilder the model type's getters and setters aren't invoked for retrieving/setting the property value when content is edited through the UI.
Instead it effectively uses the Property indexer.
This is different from how it works in Episerver 7+.
This is why your code isn't executed when that string property is edited in the UI. However, if you'd set the value through code, like CurrentPage.MainArea = "Some value"
, your setter code would execute.
To clarify, this is because PageTypeBuilder is a third-party add-on, it's not the native behavior of Episerver 6. If your website was an Episerver 7+ website, you would be able to debug your code like you expected, as it features strongly-typed content models natively.
Upvotes: 0