1

I created a custom image field, so far its working fine. but when I take an image path and add it manually to the field without clicking browse. It disappears which is not the normal behavior in OOTB image field.

enter image description here

Custom Image Field Class:

public class CustomImage : Image
{
    public string ItemID
    {
        get
        {
            return base.GetViewStateString("ItemID");
        }
        set
        {
            Assert.ArgumentNotNullOrEmpty(value, "ItemID");
            base.SetViewStateString("ItemID", value);
        }
    }

    public string FieldID
    {
        get
        {
            return base.GetViewStateString("FieldID");
        }
        set
        {
            Assert.ArgumentNotNullOrEmpty(value, "FieldID");
            base.SetViewStateString("FieldID", value);
        }
    }

    public override string Source
    {
        get
        {
            return this.GetViewStateString(nameof(Source));
        }
        set
        {
            Assert.ArgumentNotNull((object)value, nameof(value));

            string str = MainUtil.UnmapPath(value);
            if (str.EndsWith("/", StringComparison.InvariantCulture))
            {
                str = str.Substring(0, str.Length - 1);
            }
            else if (!string.IsNullOrWhiteSpace(value))
            {
                var item = Sitecore.Data.Database.GetDatabase("master").GetItem(new ID(ItemID));
                str = Query(value, item);
            }
            this.SetViewStateString(nameof(Source), str);
        }
    }

    public override void HandleMessage(Message message)
    {
        if (message["id"] != base.ID)
            return;

        if (message.Name.Equals("contentimage:customimage"))
        {
            Sitecore.Context.ClientPage.Start(this, "HandleCustomImage");
        }

        base.HandleMessage(message);
    }
}

Does anyone knows how to solve this?

Thanks in advance.

4
0

The problem was in calling the base function, it suppose to be in the beginning of the fuction.

public override void HandleMessage(Message message)
    {
        base.HandleMessage(message);

        if (message.Name.Equals("contentimage:customimage"))
        {
            Sitecore.Context.ClientPage.Start(this, "HandleCustomImage");
        }
    }

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.