SiteMapNavigationTabStrip template hyperlink not working
I've created an ascx as a template for SiteMapNavigationTabStrip.
The file contains this code:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SubMenu.ascx.cs" Inherits="RSS.Website.Custom.Templates.SubMenu" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls.SiteMapNavigations" TagPrefix="navcontrols" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
navcontrols:SiteMapNavigationTabStrip
ID
=
"MyNavigation"
runat
=
"server"
Orientation
=
"VerticalLeft"
MaxDataBindDepth
=
"1"
Skin
=
""
>
<
TabTemplate
>
<
asp:HyperLink
ID
=
"hlMenu"
runat
=
"server"
NavigateUrl='<%#DataBinder.Eval(Container, "NavigateUrl") %>' ToolTip='<%# DataBinder.Eval(Container, "Text") %>'>
<
asp:Image
ID
=
"imgMiddle"
runat
=
"server"
ImageUrl='<%# "~/DynImage.ashx?
f
=
Epitough
&
h
=
25
&fc=%23bd0926&
bgc
=
white
&
fs
=
20
&
t
=
" + DataBinder.Eval(Container, "
Text") %>' AlternateText='<%# DataBinder.Eval(Container, "Text") %>' />
</
asp:HyperLink
>
</
TabTemplate
>
</
navcontrols:SiteMapNavigationTabStrip
>
<
div
id
=
"ctl00_cphLeftColumn_T52AEF7F1001_ctl00_ctl00_MyNavigation"
class
=
"RadTabStripVertical RadTabStrip_ RadTabStripLeft_"
>
<!-- 2011.2.712.40 -->
<
div
class
=
"rtsLevel rtsLevel1"
>
<
ul
class
=
"rtsUL"
>
<
li
class
=
"rtsLI rtsFirst"
>
<
div
class
=
"rtsLink rtsBefore"
>
<
div
class
=
"rtsOut"
>
<
div
class
=
"rtsIn"
>
<
a
id
=
"ctl00_cphLeftColumn_T52AEF7F1001_ctl00_ctl00_MyNavigation_i0_hlMenu"
title
=
"Huizenpartner"
href
=
"huizenpartner"
>
<
img
id
=
"ctl00_cphLeftColumn_T52AEF7F1001_ctl00_ctl00_MyNavigation_i0_imgMiddle"
src
=
"../DynImage.ashx?f=Epitough&h=25&fc=%23bd0926&bgc=white&fs=20&t=Huizenpartner"
alt
=
"Huizenpartner"
/>
</
a
>
</
div
>
</
div
>
</
div
>
</
li
>
<
li
class
=
"rtsLI rtsLast"
>
<
div
class
=
"rtsLink rtsSelected"
>
<
div
class
=
"rtsOut"
>
<
div
class
=
"rtsIn"
>
<
a
id
=
"ctl00_cphLeftColumn_T52AEF7F1001_ctl00_ctl00_MyNavigation_i1_hlMenu"
title
=
"TipBase"
href
=
"tipbase"
>
<
img
id
=
"ctl00_cphLeftColumn_T52AEF7F1001_ctl00_ctl00_MyNavigation_i1_imgMiddle"
src
=
"../DynImage.ashx?f=Epitough&h=25&fc=%23bd0926&bgc=white&fs=20&t=TipBase"
alt
=
"TipBase"
/>
</
a
>
</
div
>
</
div
>
</
div
>
</
li
>
</
ul
>
</
div
>
<
input
id
=
"ctl00_cphLeftColumn_T52AEF7F1001_ctl00_ctl00_MyNavigation_ClientState"
name
=
"ctl00_cphLeftColumn_T52AEF7F1001_ctl00_ctl00_MyNavigation_ClientState"
type
=
"hidden"
/>
</
div
>
Any suggestions?
Hi El Barto,
To make the control work remove this:
<
TabTemplate
>
<
asp:HyperLink
ID
=
"hlMenu"
runat
=
"server"
NavigateUrl='<%#DataBinder.Eval(Container, "NavigateUrl") %>' ToolTip='<%# DataBinder.Eval(Container, "Text") %>'>
<
asp:Image
ID
=
"imgMiddle"
runat
=
"server"
ImageUrl='<%# "~/DynImage.ashx?
f
=
Epitough
&
h
=
25
&fc=%23bd0926&
bgc
=
white
&
fs
=
20
&
t
=
" + DataBinder.Eval(Container, "
Text") %>' AlternateText='<%# DataBinder.Eval(Container, "Text") %>' />
</
asp:HyperLink
>
</
TabTemplate
>
Hi Stanislav
Okay, but what is the purpose of the ascx template? I thought you could use Custom template path to customize each item in the navigation widget.
I want my own content for each item in the navigation control. What would be the way to do that?
Any help to create a custom template for the navigation widget would be appreciated.
Hi El Barto,
When using a template for Sitefinity navigation control this automatically bind the menu control to the navigation control built in sitemap that populates each item. This makes all menu items created dynamically based on how many pages are in the sitemap.
Here is the the complete code for a custom navigation control. I have added an explanation on the important topics.
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="SitefinityWebApp.Controls.WebUserControl1" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" TagPrefix="sfMap" %>
<
sfMap:SitefinitySiteMapDataSource
ID
=
"SM"
runat
=
"server"
ShowStartingNode
=
"false"
/>
<
telerik:RadMenu
ID
=
"RadMenu1"
runat
=
"server"
DataSourceID
=
"SM"
>
<%--this menu is bound to sitefinity sitemap notice the DataSourceID, all items are automatically populated--%>
</
telerik:RadMenu
>
<
telerik:RadMenu
ID
=
"RadMenu2"
runat
=
"server"
>
<
Items
>
<
telerik:RadMenuItem
Text
=
"File"
AccessKey
=
"F"
>
<%--To extend the menu I have added new menu that holds items that I specify by entering them by hand--%>
</
telerik:RadMenuItem
>
</
Items
>
</
telerik:RadMenu
>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
namespace
SitefinityWebApp.Controls
public
partial
class
WebUserControl1 : System.Web.UI.UserControl
protected
void
Page_Load(
object
sender, EventArgs e)
RadMenuItem item =
new
RadMenuItem(
"Root item text"
);
RadMenu2.Items.Add(item);
Hi Stanislav,
Thank you very much for the example.
Using your example gave me a Both DataSource and DataSourceID are defined on 'RadMenu1'. Remove one definition. exception. I removed the DataSourceID attribute from RadMenu1 and it worked. The template I use looks like this:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SubMenu.ascx.cs" Inherits="RSS.Website.Custom.Templates.SubMenu" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.NavigationControls" TagPrefix="sfMap" %>
<
sfMap:SitefinitySiteMapDataSource
ID
=
"SM"
runat
=
"server"
ShowStartingNode
=
"false"
/>
<
telerik:RadMenu
ID
=
"RadMenu1"
runat
=
"server"
Flow
=
"Vertical"
Skin
=
""
>
<%--this menu is bound to sitefinity sitemap notice the DataSourceID, all items are automatically populated--%>
<
ItemTemplate
>
<
asp:HyperLink
ID
=
"hlMenu"
runat
=
"server"
NavigateUrl='<%# DataBinder.Eval(Container, "NavigateUrl") %>' ToolTip='<%# DataBinder.Eval(Container, "Text") %>'>
<
asp:Image
ID
=
"imgMiddle"
runat
=
"server"
ImageUrl='<%# "~/DynImage.ashx?
f
=
Epitough
&
h
=
25
&fc=%23bd0926&
bgc
=
white
&
fs
=
20
&
t
=
" + DataBinder.Eval(Container, "
Text") %>' AlternateText='<%# DataBinder.Eval(Container, "Text") %>' />
</
asp:HyperLink
>
</
ItemTemplate
>
</
telerik:RadMenu
>