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

Forums / Developing with Sitefinity / Working with .net standard Menu Adaptor using sitemap of sitefinity

Working with .net standard Menu Adaptor using sitemap of sitefinity

4 posts, 0 answered
  1. Samir
    Samir avatar
    14 posts
    Registered:
    12 May 2008
    12 May 2009
    Link to this post
    Hello,

    I'm currently using sitefinity ver 3.6. I would like to use the .net 2.0 standard Menu adaptor to customize the navigation in the sitefinity site. I have been successful in doing this (just put the "DataSourceID=sitemapdatasource1") and works great except "StaticSelectedStyle-CssClass" of the menu adaptor does not work. I wanted the selected menu to have different look than the rest of the menu in the site. Is this possible without using the rad controls that sitefinity has? I think the problem with this is that the "Web.sitemap" file that sitefinity creates is dynamic and thus have "url" field different. Is this the problem for "StaticSelectedStyle-CssClass" not accepting the css styles coded in the css class it will use? If it is or any thing else casuing the problem, is there a way I can acheive what i'm trying to do. Thanks for any help.
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    14 May 2009
    Link to this post
    Hi Samir,

    Here is an example how to work around the described issue with asp.net menu:

    .ascx
    <style type="text/css"
    .selected 
        background-color: Red; 
    </style> 
     
    <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="false" /> 
    <asp:Menu ID="Menu1" runat="server" DataSourceID="SitemapDataSource1" StaticSelectedStyle-CssClass="selected" OnMenuItemDataBound="MenuItemDataBound" > 
    </asp:Menu> 

    .ascx.cs
     protected void MenuItemDataBound(Object sender, MenuEventArgs e) 
        { 
            ICmsUrlContext urlContext = CmsUrlContext.Current; 
            if (urlContext != null
            { 
                string currentUrl = SiteMapDataSource1.Provider.CurrentNode.Url; 
                MenuItem item = e.Item; 
                if (currentUrl.Equals(item.NavigateUrl, StringComparison.OrdinalIgnoreCase)) 
                { 
                    item.Text = "<span class='" + Menu1.StaticSelectedStyle.CssClass + "'>" + item.Text + "</span>"
                } 
            } 
        } 

    Do let us know if this helps.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Samir
    Samir avatar
    14 posts
    Registered:
    12 May 2008
    14 May 2009
    Link to this post
    Hi Pepi,

    Thanks for the post. Yes this does work! Thank you! Thank you.

    However, i don't know if it was a type O or may be not, but for the method: MenuItemDataBound, is "ICmsUrlContext urlContext = CmsUrlContext.Current" supposed to be:
    CmsUrlContext without the 'I'. Also, I had to comment out the 'if' condition and the above piece of code for the Menu to work because it gave me this error:

    error CS0246: The type or namespace name 'CmsUrlContext' could not be found (are you missing a using directive or an assembly reference?)

    It's a namespace error. If you would be kind enough to please send me what namcespace to use.

    One more thing I should mention is that if anyone wants to use the standard .net Menu adaptor instead of the rad controls that sitefinity comes with, the menu adaptor has to be used as a user control and upload that user control in sitefinity for it to work. Otherwise, if the standard asp menu is coded into the masterpage, it will work just fine except when you have to edit the content of the website in edit mode of the sitefinity. There, it will not find the "SitemapDataSource1" and throw an error "SitemapDataSource1" cannot be found, something like that.

    Thanks again
  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    15 May 2009
    Link to this post
    Hi Samir,

    The full name of the interface is Telerik.Cms.Web.ICmsUrlContext. For your convenience I have attached a user control which represents a full example of the required menu functionality. To test the control you need just to upload it through Sitefinity interface.

    Hope this helps.

    Best wishes,
    Pepi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Register for webinar
4 posts, 0 answered