5

I am creating a new link field in Sitecore following this link: Link for custom link field

I have successfully created one called modal link. Specifically I want to get all the modal components that are currently in the page. I need to get the page ID, so that I could get the modal component it has then list it in a combobox. Right now I'm facing a problem trying to get that ID.

My code is exactly the same as no. 6 on the link

public class GoogleEvent : Link
{
    // Sets the value.
    public void SetValue(string value)
    {
        Value = value;
    }
    // Gets the value.
    public string GetValue()
    {
        return Value;
    }
    // Handles the message.
    public override void HandleMessage(Sitecore.Web.UI.Sheer.Message message)
    {
        //Hopefully get page ID here then pass it

        base.HandleMessage(message);
        if (message["id"] != ID || String.IsNullOrEmpty(message.Name))
        {
            return;
        }
        switch (message.Name)
        {
            case "contentlink:GoogleEvent":
                var url = new UrlString(UIUtil.GetUri("control:GoogleTrackinglink"));

                //Add the page id in url here

                base.Insert(url.ToString());
                return;
        }
        if (Value.Length > 0)
        {
            SetModified();
        }
        Value = String.Empty;
    }
}

In code, getting the context item is not giving me what I need, so I'm aiming to get the url because on Experience Editor, the page id is stated there.

example image of the url with page identer image description here

Another problem occurs when trying to get the url is, I'm getting the source of the iframe dialog instead of the page url.

I've tried WebUtil.GetRequestUru, HttpContext.Current.Request, etc. They all return the same url, which is from the iframe dialog.

If you have questions about the code, I'm just using the codes given on the link. Is there a way to pass the url before going in to code?

3
  • You need the item id on where the link has been click or the id within the dialog? Commented Feb 13, 2018 at 14:33
  • I need the item id on where the link component is placed in. Basically the page item Id.
    – qwert
    Commented Feb 13, 2018 at 15:18
  • From the code for the Dialog window, can't you get the item Id? Commented Feb 13, 2018 at 15:42

1 Answer 1

1

If you have done all the configuration as per the shared link only then as per point 5, you must have added contentlink:GoogleEvent(id=$Target).

I am not sure about custom control but the same syntax has been used to get context item in commands like delete.

Please check the value of message["id"], it might be the same which you are looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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