3

I have created a composite control in Sitecore 9 and I can use that in template editor when adding new fields.

enter image description here

This control is supposed to show an Image control where I can browse and select images but I can't see any browse button.

enter image description here

Out of the box image control shows these options

enter image description here

my code

public class CustomImage : Sitecore.Web.UI.HtmlControls.Control
{
    public CustomImage()
    {
        this.Class = "scContentControl";
        base.Activation = true;
    }
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!Sitecore.Context.ClientPage.IsEvent)
        {
            var image = new Sitecore.Shell.Applications.ContentEditor.Image();
            this.Controls.Add(image);

        }
        else
        {
        }
    }
}

I could not find any example on how to add image control in composite control, so code is very basic.

Once I get this working, my goal is to have 4 image controls in one composite control.

0

When you created your new field type CustomImage in core db, make sure you have the folder Menu inside the field.

This contains the options that you want to appear on the Content Editor for the specific field.

See screenshot below of how the OOTB image field of Sitecore is.

enter image description here

You can find the image field in /sitecore/system/Field types/Simple Types in core db.

In your code, you are only telling sitecore that the type of the control is Image.

I was able to replicate your issue without the Menu folder. See below screenshots.

Custom Image in core db. enter image description here

Field appearing without any options. enter image description here

After adding the Menu with the specific actions, here is the result.

enter image description here

enter image description here

Please note that if you copy the Menu Items from the Image field, they will not work as the Image field is defined differently.

I strongly recommend you to see how the OOTB sitecore Image field has been built.

  • How would this work for multiple custom image controls? – Ali Sep 17 '18 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.