volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

AI OnAI Off

Default Property Values in code?

I have a property set up like so:

[Editable(true)]
[Display(
      Name = "Show Foo",
      Description = "Show or hide page Foo",
      GroupName = SystemTabNames.Settings,
      Order = 2
)]
public virtual bool ShowFoo{ get; set; }


How do I set the default value to true? I know I can do this in Admin Mode, but I'm hoping I can do it in code. There's a box on the Page Type Property Editor regarding default values. There has to be something that sets that right?

#66201
Feb 22, 2013 20:20
Vote:

 Hi Corbin, try to do like this

 public override void SetDefaultValues(ContentType contentType)
        {
            base.SetDefaultValues(contentType);
            //Set up your defaults here 
          this.ShowFoo = true;
       }

I hope it helps you.
#66202
Edited, Feb 22, 2013 20:58

That did it. Thanks.

#66203
Feb 22, 2013 22:45
error 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.