Implementing the field control class

You must always inherit from the FieldControl class. There are some abstract methods and properties you have to override.

public class MyCustomFieldControl : FieldControl
{
    // your implementation goes here
}

InitializeControls method

As with all Sitefinity widgets that inherit from SimpleView, you must override the InitializeControls method. You can think of this as an alternative of the CreateChildControls method in custom ASP.NET controls. You can implement your control’s logic here.

protected override void InitializeControls(GenericContainer container)
{
    // your server logic goes here
}

TitleControl property

This property should return a control from the template of your field control, which will display the title. All field controls have a title, displayed in the backend form when in Write mode. You can use the Container.GetControl() generic method that is available in all Sitefinity widgets inheriting from SimpleView, and just supply the ID. You can have a different title control in Read and Write mode.

protected override WebControl TitleControl
{
    get
    {
        if (this.DisplayMode == FieldDisplayMode.Read)
            return this.Container.GetControl<WebControl>("titleLabel_read", true);
        else
            return this.Container.GetControl<WebControl>("titleLabel_write", true);
    }
}

DescriptionControl property

DescriptionControl should return a control from the template, which will display the description of your custom field control. As with the TitleControl, you can have a different description in Read and Write mode.

protected override WebControl DescriptionControl
{
    get
    {
        if (this.DisplayMode == FieldDisplayMode.Read)
            return this.Container.GetControl<WebControl>("descriptionLabel_read", true);
        else
            return this.Container.GetControl<WebControl>("descriptionLabel_write", true);
    }
}

ExampleControl property

ExampleControl should return a control from the template, which will display an example of the value that your field control expects from the user.

protected override WebControl ExampleControl
{
    get
    {
        if (this.DisplayMode == FieldDisplayMode.Read)
            return this.Container.GetControl<WebControl>("exampleLabel_read", true);
        else
            return this.Container.GetControl<WebControl>("exampleLabel_write", true);
    }
}

LayoutTemplateName property

This is not specific to field controls, but all widgets that inherit from SimpleView. You can return null in your project.

protected override string LayoutTemplateName
{
    get { return null; }
}

LayoutTemplatePath property

Although it is not abstract, we recommend that you override the LayoutTemplatePath property. Here, similar to all widgets in Sitefinity, you should return a path to the template used by your field control. You can either use a path to an embedded resource (recommended), or an external file. For more information, you can read about the VirtualPathProvider.

public override string LayoutTemplatePath
{
    get
    {
        return MyCustomFieldControl.layoutTemplatePath;
    }
    set
    {
        base.LayoutTemplatePath = value;
    }
}
 
private const string layoutTemplatePath = "~/MyPrefix/Telerik.Sitefinity.Samples.MyCustomFieldControl.ascx";

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK