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

Forums / Developing with Sitefinity / Template Error when opening external page to new window

Template Error when opening external page to new window

4 posts, 0 answered
  1. Jackie
    Jackie avatar
    2 posts
    Registered:
    14 Feb 2011
    14 Feb 2011
    Link to this post
    public void RadPanelbar1_ItemDataBound(object sender, RadPanelBarEventArgs e)
       {
           CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode; 
           if (this.hideUrlForGroupPages)
           {
                 
               if (node != null && node.PageType == CmsPageType.Group)
               {
                   e.Item.NavigateUrl = "";
               }
           }
           if (node.CmsPage.PageType == CmsPageType.External)
           e.Item.Target = "_blank";
                       
       }
     I added the code above to sitepanelbar.acsx.cs to open external pages to a new window.  It works great from the page but when I attempt to edit any template that has the Site Panel Bar, I get error attached to this thread.  Any ideas.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Feb 2011
    Link to this post
    Hello Jackie,

    The node or CmsPage is null in your case. The node could be null if there is no data item

    CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode;

    You can also use PageType directly instead of making reference to the CmsPage.

    if(node.PageType == CmsPageType.External)
            {
                e.Item.Target = "_blank";
            }

    Kind regards,
    Ivan Dimitrov
    the Telerik team
  3. Jackie
    Jackie avatar
    2 posts
    Registered:
    14 Feb 2011
    18 Feb 2011
    Link to this post
    Your suggested code works to open the external links in a new window, but again the templates that have a sitepanel throw an error, very similar to the previous error.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Feb 2011
    Link to this post
    Hello Jackie,

    Please run the code in VS debugger and see which object is null. Then you can create it or escape it with an if loop.

    Regards,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Register for webinar
4 posts, 0 answered