Custom Navigation, Sitemap caching issues?
Ok, I've got a strange one. I've implemented a custom navigation control that uses a RadTabStrip to show top-level navigation items. Whenever a user is on the top-level page OR any of it's children, a CSS style is applied to the particular tab.
The problem is that after a while, the "selected" CSS is no longer applied to the menu. If I simply go to any page in the back-end, MAKE NO CHANGES, but simply push "Publish", everything begins to work exactly as intended.
This makes me believe that there is some kind of cache dependency that fails to return a proper value when I check to see if my child page is a descendant of the top-level page. Here is my code:
ASCX:
<
asp:Label
runat
=
"server"
ID
=
"lblNotVisible"
Text
=
"This control is not visible in design mode"
Visible
=
"false"
></
asp:Label
>
<
telerik:RadTabStrip
ID
=
"rtsMainMenu"
runat
=
"server"
EnableEmbeddedSkins
=
"false"
EnableEmbeddedBaseStylesheet
=
"false"
EnableSubLevelStyles
=
"false"
DataSourceID
=
"SiteMap"
MaxDataBindDepth
=
"1"
OnTabDataBound
=
"rtsMainMenu_TabDataBound"
>
</
telerik:RadTabStrip
>
<
asp:SiteMapDataSource
runat
=
"server"
ID
=
"SiteMap"
StartFromCurrentNode
=
"false"
ShowStartingNode
=
"false"
StartingNodeOffset
=
"0"
/>
01.
private
readonly
SiteMapNode cn = SiteMapBase.GetCurrentProvider().CurrentNode;
02.
protected
void
Page_Load(
object
sender, EventArgs e)
03.
04.
if
(
this
.IsDesignMode())
05.
06.
rtsMainMenu.Visible =
false
;
07.
lblNotVisible.Visible =
true
;
08.
09.
10.
11.
12.
protected
void
rtsMainMenu_TabDataBound(
object
sender, RadTabStripEventArgs e)
13.
14.
if
(!
this
.IsDesignMode())
15.
16.
17.
RadTab t = e.Tab;
18.
var data = t.DataItem
as
PageSiteNode;
19.
20.
if
(cn.IsDescendantOf(data))
21.
t.CssClass =
"rtsLink rtsSelected"
;
22.
23.
24.
25.
try
26.
27.
28.
if
(data !=
null
)
29.
30.
31.
if
(data.ShowInNavigation ==
false
)
32.
33.
t.Visible =
false
;
34.
35.
36.
37.
38.
catch
(Exception)
39.
40.
41.
else
42.
43.
RadTab t = e.Tab;
44.
t.Visible =
false
;
45.
46.
47.
Hi Amir,
i am not sure what is causing this. I have tested the control at my end and no styles were applied before removing EnableEmbeddedBaseStylesheet
=
"false"
EnableSubLevelStyles
=
"false"
and the styles applied were not removed. A caching issue might occur if you modify the css applied to the menu item (for example the page frontend theme) and the previous styles might get applied, but not the one you just edited. Publishing a page fixes this. As a possible solution try telling the tabstrip if(SystemManager.IsDesignMode)
and to better determine if some caching occur can you temporary disable caching on the page with the navigation?
Stanislav,
Sorry, I should've included my overridden CSS.. Please see below. However, to try and reproduce it, you should look for the ADDITIONAL "rtsSelected" class appended to the currently chosen item. That's the main problem. At some point the code STOP applying the "rtsSelected" class. I don't think It's a css cache issue, because if you look at the rendered document, the "rtsSelected" doesn't exist for ANY of the tabs.
Here is the CSS:
.RadTabStrip, .RadTabStrip .rtsUL
font-family
:
Arial, Helvetica, sans-serif;
text-transform
:
lowercase
;
font-size
:
15px
;
height
:
40px
;
float
:
left
;
.rtsTxt
font-family
:
Arial, Helvetica, sans-serif;
.RadTabStrip .rtsUL .rtsLI
position
:
relative
;
float
:
left
;
.RadTabStrip .rtsUL .rtsLI .rtsLink
color
:
white
;
line-height
:
33px
;
.RadTabStrip .rtsLI a
background
:
none
repeat
scroll
0
0
#000000
;
display
:
block
;
height
:
30px
;
text-align
:
center
;
width
:
130px
;
.RadTabStrip .rtsLI + .rtsLI a
background
:
none
repeat
scroll
0
0
#3552A6
;
display
:
block
;
height
:
30px
;
text-align
:
center
;
width
:
109px
;
.RadTabStrip .rtsLI + .rtsLI + .rtsLI a
background
:
none
repeat
scroll
0
0
#66BE3E
;
display
:
block
;
height
:
30px
;
text-align
:
center
;
width
:
109px
;
.RadTabStrip .rtsLI + .rtsLI + .rtsLI + .rtsLI a
background
:
none
repeat
scroll
0
0
#BA4FA0
;
display
:
block
;
height
:
30px
;
text-align
:
center
;
width
:
170px
;
.RadTabStrip .rtsLI + .rtsLI + .rtsLI + .rtsLI + .rtsLI a
background
:
none
repeat
scroll
0
0
#F01914
;
display
:
block
;
height
:
30px
;
text-align
:
center
;
width
:
125px
;
.RadTabStrip .rtsUL .rtsLI .rtsLink.rtsSelected
margin
:
-10px
0
0
;
padding
:
10px
0
0
;
Hello Amir,
Thank you for the css. I have not been able to reproduce the problem at my end, but I think I might have some information that will help you. rtsSelected was always applied when using the same template for the pages in navigation. When changed the template for one of the page to use Sitefinity basic theme the navigation stopped working properly on this page. By default Sitefinity templates have a theme applied to them that contains styles for all types of Rad Controls. If you want to use Sitefinity basic theme and use some personalized styling for the navigation use !important on the classes that are not applied or create your theme and then you will not need to use !important.
I suppose the missing of rtsSelected is because an overwritten css from a theme. Can you try adding !important for the properties of your .rtsSelected?
Greetings,
Stanislav Velikov
the Telerik team