Umbraco Backoffice default values

Posted 5 Feb 17 by Darren Welch

A feature that is really useful in umbraco is the ability to override the backoffice and give default values to your controls. 


This is extremely useful if you have a value that will be the same for 90% of instances.


In our example we will be using Umbraco version 7.


Let's pretend we are building a job listing website. 


So our document type has a job expiration date and we want it to pre-populate with 30 days by default.Closing date


You will need to create a class in your models folder and override the ContentService_Created event.


Here's how the code will look:


(I have named my class umbEvents, but you can name yours whatever you like).

public class umbEvents : IApplicationStartupHandler { public umbEvents() { ContentService.Created += ContentService_Created; } void ContentService_Created(IContentService sender, Umbraco.Core.Events.NewEventArgs e) { if (e.Alias == "Jobitem") { e.Entity.SetValue("closingDate", (DateTime.Now.AddDays(28))); } } }


You can now set a break point and step through your code.

Darren Welch


Darren Welch

  5 Feb 17

Contact me online



 Linked In

 Git Hub

Related Content

Create circular images with CSS

05 Feb 2017

Creating HTML Helpers

05 Feb 2017

Umbraco - RTE - Add blockquotes

05 Feb 2017