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 id
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?