Sitemap contains links : Even after "Show in navigation" unchecked
Installed Sitefinity_4.1.1501.0
Sitemap contains links : Even after "Show in navigation" unchecked. Why?
<asp:SiteMapDataSource ID="SiteMapDataSource1" ShowStartingNode="false" runat="server" />
<radM:RadMenu ID="RadMenu1" runat="server" DataSourceID="SitemapDataSource1" Skin="menu1" >
Hello Justin,
Remove SiteMapDataSource from your template and set NavigationControl to use your ascx.
Best wishes,
Ivan Dimitrov
the Telerik team
I'm not sure I understand. We also want to use the same code Justin used (as we have code behind that needs to be associated with the menu in order to get images as the first level of nav).
We got it working fine, but when we add a page to the sitemap and say do not show in nav it still appears in this menu.
Any other idea?
Hi Ben Alexandra,
You can follow Ivan's advice and create your control, which you can later set as a template for the Navigation widget in Sitefinity - you simply create the presentation part (ascx) and the codebehind logic of your control, compile it, but you will not be feeding it with a datasource, as you'll specify its application relative path to the Custom Template Path property int eh design setting s of the Navigation widget. This will automatically feed your widget with the datasource provided for all Sitefinity navigation controls, and solve your problems with the ShowInNavigation pages.
However, if you need to add a datasource declaratively to your control, please use our newly introduced SitefinitySiteMapDataSource control (available since release version Sitefinity 4.2 build 4.2.1650)
If you're still using a previous version of Sitefinity, where this control is not available, you can still use asp:SiteMapDataSource control and perform the following check in your codebehind:
ISitefinitySiteMapNode cNode = e.Item.DataItem asISitefinitySiteMapNode;
PageSiteNode node = (PageSiteNode)cNode;
if
(!node.ShowInNavigation || !node.Visible)
e.Item.Visible =
false
;
Hi,
So I work with Ben from above. We followed your instructions and we were
able to create a menu user control, which we applied as a template to
the Sitefinity Navigation user control. All of that worked perfectly and
the pages that we set to hide in the navigation are now hidden
correctly. However, we are having another issue. We want to use images
for the RadMenu items rather than text. This works fine with the code we
are using in the code behind if we put the menu on the master template.
The problem with that method is that we had to use a data source and so
we had the original issue with menu items no hiding when they were
supposed to. Your solution (i.e., creating a control and using it as a
Custom template path) fixes that problem but when put the exact same
code behind in that control, the images no longer work. Our menu now
just shows text. Here is the markup we used in the .ascx page for the
custom template:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TopMenuViewCustom.ascx.cs" Inherits="Trakkware.Clients.EasternCurrents.easterncurrents.ca.Sitefinity.UserControls.Trakkware.TopMenuViewCustom" %>
<
telerik:RadMenu
ID
=
"EasternCurrentsTopMenu"
runat
=
"server"
></
telerik:RadMenu
>
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;
using Telerik.Web.UI;
using System.IO;
namespace Trakkware.Clients.EasternCurrents.easterncurrents.ca.Sitefinity.UserControls.Trakkware
public partial class TopMenuViewCustom : System.Web.UI.UserControl
protected void Page_Load(object sender, EventArgs e)
// Hide the radmenu in edit mode.
string path = HttpContext.Current.Request.Url.AbsolutePath;
SiteMapNode smnRoot = SiteMap.RootNode;
SiteMapNode smnCurrentParent = SiteMap.CurrentNode;
if (path.IndexOf("/Action/Edit") != -1 || path.IndexOf("/Sitefinity") != -1)
EasternCurrentsTopMenu.Visible = false;
else
while (smnCurrentParent.ParentNode != smnCurrentParent.RootNode) smnCurrentParent = smnCurrentParent.ParentNode;
RadMenuItem item = new RadMenuItem();
EasternCurrentsTopMenu.DataBind();
smnRoot = smnRoot.ChildNodes[0];
while (smnRoot != null)
item = EasternCurrentsTopMenu.FindItemByUrl(ResolveUrl(smnRoot.Url));
if (item != null)
String strTitle = smnRoot.Title.ToLower().Replace(" ", "_").Replace("ü", "u").Replace("ä", "a").ToString();
String strImageOver = String.Format("~/images/template/menu/0-over.jpg", strTitle);
String strImage = String.Format("~/images/template/menu/0.jpg", strTitle);
//Added by Ben to see if item exist
if (File.Exists(Server.MapPath(strImage)))
if (smnRoot == smnCurrentParent)
item.ImageUrl = strImageOver;
else
item.ImageUrl = strImage;
item.HoveredImageUrl = strImageOver;
item.ToolTip = smnRoot.Title.ToString();
item.Text = "";
smnRoot = smnRoot.NextSibling;
Hello Martin Chamorro,
Have you considered the option of upgrading your project to the latest officially supported version? I'm suggesting this, as you could benefit from using our SitefinitySiteMapDatasource control which wraps all the necessary logic (permissions check, ShowInNavigation, Group pages redirect, Group pages with no children etc.) You can use it as a DataSource for your control, and then implement just the logic for assigning an image to an item int he Navigation. You can check a sample of using SitefinitySiteMapDataSource below:
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" TagPrefix="sfMap" %>
<
sfMap:SitefinitySiteMapDataSource
runat
=
"server"
ID
=
"SitefinitySiteMapDS"
StartingNodeUrl
=
"/Home"
/>
<
telerik:RadTreeView
runat
=
"server"
ID
=
"RTV1"
DataSourceID
=
"SitefinitySiteMapDS"
></
telerik:RadTreeView
>