Try our conversational search powered by Generative AI!

Setting default values in block type



I'm trying to set some default values for some properties in epi seerver 7.
I have this method in my block type:

    public override void SetDefaultValues(ContentType contentType)

        Title = "Default title";

But it isn't even called. I followed this guide:

Can anyone help?

May 02, 2013 9:47

Can you post some more of your block type definition code?

May 02, 2013 10:50

Can it be that you try this on already created block? EPiServer default values are only set when you create a new page / block.

May 02, 2013 10:57
May 02, 2013 10:59

Per Nergård was right. I was doing it on a block I already had created. Is it any way to say: if this property is blank, use this value?

May 02, 2013 11:01

Something like this can get you that behavior:

public virtual string Whatever
get { return this.GetPropertyValue(page => page.Whatever) ?? "a default value to return"; }
set { this.SetPropertyValue(page => page.Whatever, value); }


May 02, 2013 11:06

Nice, thanks! I tried to make custom setters and getters first, but I didn't use this.GetPropertyValue so it didn't work. Now it works!

EDIT: Would it be possible to set those defaults from episerver? 

Edited, May 02, 2013 12:26
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.