More in this section

Forums / Developing with Sitefinity / Getting ID of page group

Getting ID of page group

4 posts, 0 answered
  1. Jenn Bohm
    Jenn Bohm avatar
    17 posts
    Registered:
    19 Aug 2009
    15 Mar 2010
    Link to this post
    I was trying to use UrlHelper.GetUrl(string, bool) to get the URL of a page group, ultimately to get the ID of the page group and programmatically add a page under it. I was using a value for "url" of "/subdomain/pagegroupname". When I did this, and there were no existing pages in the page group, GetUrl returned null. Out of curiosity, I added a page to the page group manually, through the dashboard. Then, when I ran my code again, I had no problem.
    So, it looks like GetUrl will only get the URL of a page group if it contains pages. Is this the case, and if so, is this by design? Fortunately, we will have some default pages in this particular page group before the user will be using the page I'm developing, so we won't have this problem. However, it seems reasonable to want to be able to programmatically add pages to an empty page group.
    Am I missing something here?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Mar 2010
    Link to this post
    Hello Jenn Bohm,

    Thank you for using our services.

    The design of Page Groups is such that they automatically redirect to their first child page. So trying to get a page using this approach is expected to return null if the page group has not children. What will happen is that your code will try to return the first child page rather than the page group and will return null if there are no pages under it. What you can do is to take any child page of the PageGroup using your approach. Then this child page will have .Parent property which you can access.

    All the best,
    Radoslav Georgiev
    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. Jenn Bohm
    Jenn Bohm avatar
    17 posts
    Registered:
    19 Aug 2009
    15 Mar 2010
    Link to this post
    Thanks for the reply.
    So, what is the recommended way to get the ID of a page group, whether it has child pages or not?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    15 Mar 2010
    Link to this post
    Hello Jenn Bohm,

    If this is standard ICmsPage ( normal page) the only way is checking whether this object has children.
    If the page is of type Group you can use the API to determine the type, then get the ID.

    sample

    CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode;
    if (currentNode.PageType == CmsPageType.Group)
    {
         //do something
    }


    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
4 posts, 0 answered