RadMenu loading user controls not working

2 posts, 0 answers
  1. Ashley
    Ashley avatar
    5 posts
    Member since:
    Nov 2014

    Posted 22 Jan 2015 Link to this post

    I am attempting to load user controls inside a PlaceHolder using a RadMenu. Ajax manager is updating both the menu and the placeholder. When I click on the menu item nothing happens. Initially, when the page loads the homeview.ascx user control does load, but it is not updated on menuitem click.

     ASPX Page

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
                            <AjaxSettings>
                                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                                    <UpdatedControls>
                                        <telerik:AjaxUpdatedControl ControlID="MainNav" />
                                        <telerik:AjaxUpdatedControl ControlID="BodyContent" LoadingPanelID="RadAjaxLoadingPanel1" />
                                    </UpdatedControls>
                                </telerik:AjaxSetting>
                            </AjaxSettings>
                        </telerik:RadAjaxManager>
                    <!-- Main Menu -->
                        <div class="menu-wrapper" style="border-top: solid 40px #b1ddab;">
                            <telerik:RadMenu runat="server" ID="MainNav" EnableEmbeddedSkins="false" OnItemClick="MainNav_OnItemClick" CssClass="desktop_nav_menu" >
                                <Items>
                                    <telerik:RadMenuItem Text="<%$ Resources:Main, MasterHome %>" />
                                    <telerik:RadMenuItem Text="<%$ Resources:Main, MasterTraining %>" />
                                    <telerik:RadMenuItem Text="<%$ Resources:Main, MasterSupport %>" />
                                </Items>
                            </telerik:RadMenu>
                        </div>             
                    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel>
                    <asp:PlaceHolder ID="BodyContent" runat="server">
                          
                    </asp:PlaceHolder>


    Code Behind

    protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadView();
        }
     
    private string LoadedControlName
        {
            get
            {
                return (this.ViewState[ViewStateKeys.LoadedControlName] as string) ?? defaultContentControl;
            }
            set
            {
                this.ViewState[ViewStateKeys.LoadedControlName] = value;
            }
        }
     
    private void LoadView()
        {
            this.LoadView(this.LoadedControlName);
        }
     
        private void LoadView(string viewName)
        {
            Control control = this.LoadControl(string.Concat(SitePaths.Views, viewName));
            control.ID = viewName;
            this.LoadedControlName = viewName;
            this.BodyContent.Controls.Clear();
            this.BodyContent.Controls.Add(control);
        }
     
        public void MainNav_OnItemClick(object sender, RadMenuEventArgs e)
        {
            RadMenuItem currentItem = e.Item;
            string currentItemText = currentItem.Text;
            string controlPath = string.Empty;
            switch (currentItemText)
            {
                case ("Home"):
                    controlPath = DefaultViews.Home;
                    break;
                case ("Training"):
                    controlPath = DefaultViews.Training;
                    break;
                case ("Support"):
                    controlPath = DefaultViews.Support;
                    break;
                default:
                    break;
            }
            if (!String.IsNullOrEmpty(controlPath))
            {
                this.LoadView(controlPath);
            }
        }

    View Constants

    public class SitePaths
    {
        public const string Views = "~/Views/";
    }
     
    public class ViewStateKeys
    {
        public const string LoadedControlName = "LoadedControlName";
    }
      
    public class DefaultViews
    {
        public const string Home = "HomeView.ascx";
        public const string Training = "TrainingView.ascx";
        public const string Support = "SupportView.ascx";
    }

  2. Ashley
    Ashley avatar
    5 posts
    Member since:
    Nov 2014

    Posted 23 Jan 2015 Link to this post

    I figured it out myself.

    I had the radmanager configuration wrong.

    Corrected Code

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
                            <AjaxSettings>
                                <telerik:AjaxSetting AjaxControlID="MainNav">
                                    <UpdatedControls>
                                        <telerik:AjaxUpdatedControl ControlID="BodyContent"/>
                                    </UpdatedControls>
                                </telerik:AjaxSetting>
                            </AjaxSettings>
                        </telerik:RadAjaxManager>
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top