Vince Scordino Team : Web Development Tags : Web Development

Creating Umbraco Custom Data Types

Vince Scordino Team : Web Development Tags : Web Development

Umbraco come with many expected and resourceful built in data types to setup your website CMS. However, there may be a time when you’ll need to create a custom data type to implement some logic and save data where an existing data type just won’t cut in.

In this example, I’ve implemented a simple dropdown list of values, where the data populating the dropdown is derived from a 3rd party service.

Firstly, create a user control, simple! Next, you’ll need to implement the interface:

umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor

 

Once implemented, add your dropdown list control and populate with values as normally would.

The save happens when Umbraco causes a postback after the user save’s their selection. This is when we’ll need to set the new implemented properties value on Page_Load():

private string UmbracoValue;

 

protected void Page_Load(object sender, EventArgs e)

{

    if (Page.IsPostBack)

    {

        UmbracoValue = ddlVideos.SelectedValue;

    }

}

 

public object value

{

    get

    {

        return UmbracoValue;

    }

    set

    {

        UmbracoValue = value.ToString();

    }

}

 

So how can I now use this usercontrol as a datatype? Easy, create a new datatype and give it a name.

Once saved, select “umbraco usercontrol wrapper” as the Render Control.

You’ll then be able to select the Database datatype dependant on the data your saving, along with the usercontrol you’ve just created, in this case “Nvarchar”. That’s it!