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

Forums / Bugs & Issues / Custom navigation template disappears on postback

Custom navigation template disappears on postback

2 posts, 1 answered
  1. Richard Baugh
    Richard Baugh avatar
    201 posts
    Registered:
    22 Aug 2012
    05 May 2011
    Link to this post
    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;
                        }
                    }
                }
            }
        }
    }

    When I use the built-in form control and submit the form, the page will reload but the navigation does not. If I remove the custom template, then the menu will show when the post occurs. Am I missing something in my template that is causing this, or is this something with the NavigationControl?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    11 May 2011
    Link to this post
    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
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
2 posts, 1 answered