1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / How to get the PageId from within a ControlDesigner?

How to get the PageId from within a ControlDesigner?

8 posts, 0 answered
  1. Andy
    Andy avatar
    62 posts
    Registered:
    01 Aug 2008
    01 Mar 2010
    Link to this post
    I have a custom ControlDesigner for my custom Sitefinity Control.

    That ControlDesigner needs to know the Sitefinity PageId of the page that the control has been placed on, but I'm having real problems getting hold of that information!

    The property dialogue and designer runs in a seperate RadWindow, so is not in the sitemap, so I can't use:
        (CmsSiteMapNode)SiteMap.CurrentNode;
    to get it.

    And I can't seem to automatically set the PageId into a CmsPersistable property which is then visible to the Designer.

    Any clues on how best to make the Cms PageId accessible to the ControlDesigner?

    Thanks!
    Andy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    01 Mar 2010
    Link to this post
    Hello Andy,

    You can get the current page from ICmsUrlContext

    ICmsUrlContext pageKey = (ICmsUrlContext)this.Context.Items[Telerik.Cms.Web.UrlHelper.CmsPageKey];
    Guid currentPageID = pageKey.PageID;

    or from the CmsHttpRequest

    var cmsRequest = (CmsHttpRequest)this.Context.Items["CmsHttpRequest"];
    string id = cmsRequest.QueryStirng["sfpageid"];

    Telerik.Cms.Web.CmsRequest  pageKey = (Telerik.Cms.Web.CmsRequest)this.Context.Items["CmsHttpRequest"];
    string key = pageKey.ToString();
    int val = key.IndexOf("sfpageid");
    int gid = val +9;
    string ID = key.Substring(gid, 36);
    Guid id = new Guid(ID);


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Andy
    Andy avatar
    62 posts
    Registered:
    01 Aug 2008
    26 Mar 2010
    Link to this post
    Thanks Ivan.

    That did the trick in that instance.

    However, I now need the PageId in a different place - from within the image selector dialog...

    My requirement is to provide a modified popup dialog from the HTML edit areas for choosing images from libraries.
    Depending on which page the content is for (i.e. which page the content control being edited is on) the popup should pre-select a specific images library and hide all the 'Choose library' stuff in the popup.

    So I've created custom ImageEditorDialog and ItemSelector controls, and refer to these in the ImageDialog.aspx, ImageEditorDialog.aspx, and ItemDialog.aspx

    (This covers the document selector as well, as it uses the same controls.)

    However I can't find an easy way to get at the PageId from there. Do you have any suggestions in this instance?

    Thank you!
    Andy

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 Mar 2010
    Link to this post
    Hello Andy,

    If you use a class that inherits from ItemSelector you could extract the ID of the page from Context.UrlReferrer

    public class CustomSelectorDialog : ItemSelector
        {
            public CustomSelectorDialog()
            {
            }
     
            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
            }
     
     
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
                var parentpageID = this.Context.Request.UrlReferrer.Query;
            }
    }

    Then you need to get the id from parentpageID .IndexOf("sfpageid");

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Andy
    Andy avatar
    62 posts
    Registered:
    01 Aug 2008
    26 Mar 2010
    Link to this post
    I should have thought of that one!

    However the next control down, ItemSelector.... is referred by ImageEditorDialog.... isn't it?

    So I have to append the pageId to the ImageEditorDialog url somehow....? (And that's buried in the JavaScript)

    I'll work on it, but any cunning ideas in the meantime....?

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 Mar 2010
    Link to this post
    Hello Andy,

    this.Context.Request.UrlReferrer.Query will return the ID directly. You should not pass the ID's between RadWindow dialogs.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Andy
    Andy avatar
    62 posts
    Registered:
    01 Aug 2008
    26 Mar 2010
    Link to this post

    But I do!

    the Context.Request.UrlReferrer of ItemSelector is 

    Sitefinity/UserControls/Dialogs/ImageEditorDialog.aspx

    It's nested in an iframe within ImageEditorDialog!

    ??

    Thanks!
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    26 Mar 2010
    Link to this post
    Hi Andy,

    Take a look at the attached screenthot to see what is returned at my end. Also the iframe and each RadWondow is another page. If this does not work for you you need to perform cross widow data posting.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
8 posts, 0 answered