Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Setting default values in block type

Vote:
 

Hello!

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)
    {
        base.SetDefaultValues(contentType);

        Title = "Default title";
    }

But it isn't even called. I followed this guide:
http://world.episerver.com/Blogs/Alexander-Haneng/Dates/2012/9/How-to-define-default-values-for-pages-and-blocks-in-EPiServer-CMS-7/

Can anyone help?

#70837
May 02, 2013 9:47
Vote:
 

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

#70840
May 02, 2013 10:50
Vote:
 

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

#70842
May 02, 2013 10:57
Vote:
 
#70843
May 02, 2013 10:59
Vote:
 

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?

#70844
May 02, 2013 11:01
Vote:
 

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); }
}

 

#70850
May 02, 2013 11:06
Vote:
 

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? 

#70858
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.