Sitefinity CMS

Open External Page in New Window Send comments on this topic.
How-to > Pages > Open External Page in New Window

Glossary Item Box

When using an external page in Sitefinity, opening the page means leaving the current project. The only way to go back to the project is to use the Back button of the browser. In order to provide easier manipulation of both the current project and the given external page, you need to open the external page in a new window. This topic will show what should be changed to implement this functionality. 

 

Solution Code

The following code checks if the page is of type "External". If so, it states that the target should be displayed in a new window: 

Set Target Window Copy Code
if (node.CmsPage.PageType == CmsPageType.External)
 e.Item.Target =
"_blank";

 

Adding Code to the Project

The SitePanelbar control provided by Sitefinity functions similarly to the RadPanelbar control but its source code is available to all customers and is thus easy to customize it. To do that, the code-behind file must be accessed: SitePanelbar.ascx.cs, with path: /<your_project>/Sitefinity/UserControls/Navigation/

 

In its Methods region, there is a method called RadPanelbar1_ItemDataBound.  It is used to hide the URL of Group pages. In order for this behavior to take effect, the hideUrlForGroupPages property of the navigation control should be set first. This could be done by opening the page that uses the control, entering Edit mode of the page, and clicking the "Edit" link of the control. The property is in the Behavior section.

 

The following code checks if the page is a group page. After that, it checks if the page is an external page, and if yes, the setting takes place - the external page is opened in a new window:

RadPanelbar1_ItemDataBound() Copy Code
public void RadPanelbar1_ItemDataBound(object sender, RadPanelbarEventArgs e)
{
 CmsSiteMapNode node = e.Item.DataItem
as CmsSiteMapNode;
 
if (this.hideUrlForGroupPages)
 {
   
if (node != null && node.CmsPage.PageType == CmsPageType.Group)
   {
     e.Item.NavigateUrl =
"";
   }
 }
 
if (node.CmsPage.PageType == CmsPageType.External)
   e.Item.Target =
"_blank";
}

 

The example code in this topic is for the RadPanelbar control but the implementation is analogical for all navigation controls.