Custom navigation template disappears on postback
I have found an issue where the navigation control does not display when I set the custom template for the NavigationControl and a post back occurs. I am using the standard NavigationControl with the type set to horizontal with drop down. I then set the Custom template path for the control. I am using the following code for my template:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="menu.ascx.cs" Inherits="SitefinityWebApp.Sitefinity.ControlTemplates.Navigation.menu" %>
<
telerik:RadMenu
ID
=
"radMenu"
runat
=
"server"
EnableEmbeddedSkins
=
"false"
>
</
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.Sitefinity.Web;
using
Telerik.Sitefinity.Web.UI;
using
Telerik.Web.UI;
namespace
SitefinityWebApp.Sitefinity.ControlTemplates.Navigation
public
partial
class
menu : System.Web.UI.UserControl
protected
override
void
CreateChildControls()
base
.CreateChildControls();
if
(
this
.BindingContainer.BindingContainer
is
Telerik.Sitefinity.Web.UI.NavigationControls.NavigationControl)
Telerik.Sitefinity.Web.UI.NavigationControls.NavigationControl navControl = (Telerik.Sitefinity.Web.UI.NavigationControls.NavigationControl)
this
.BindingContainer.BindingContainer;
if
(navControl !=
null
)
this
.radMenu.MaxDataBindDepth = navControl.MaxDataBindDepth;
protected
void
radMenu_ItemDataBound(
object
sender, RadMenuEventArgs e)
if
(e.Item.Level > 0)
e.Item.Text = e.Item.Text.ToUpper();
protected
void
Page_Load(
object
sender, EventArgs e)
protected
override
void
OnPreRender(EventArgs e)
base
.OnPreRender(e);
SiteMapNode node = SiteMapBase.GetCurrentNode();
if
(node !=
null
)
RadMenuItem item =
this
.radMenu.FindItemByUrl(
this
.ResolveUrl(node.Url));
if
(item !=
null
)
item.Selected =
true
;
item.HighlightPath();
while
(!(item.Parent
is
RadMenu))
item = (RadMenuItem)item.Parent;
Hi Richard Baugh,
I am not sure that the CreateChildControls override will execute. This method is introduced in our classes and is not part of the UserControl class from .NET. Instead you should override the OnInit event of your user control. Then you should cast this.Parent to NavigationControl as the user control class is being held by the Container poperty of the navigation control.
Kind regards,
Radoslav Georgiev
the Telerik team