More in this section

Forums / Developing with Sitefinity / The ViewMode is not defined for this control

The ViewMode is not defined for this control

2 posts, 0 answered
  1. CafeDelMar
    CafeDelMar avatar
    28 posts
    Registered:
    06 May 2007
    19 Jun 2010
    Link to this post
    Dear Telerik Team

    I use radpanelbar to navigate all my sub view

    I have issue when navigate view, it show error message

    The ViewMode "AdminView" is not defined for this control


    Almost two months i didn't find the solution for this

    I 've already follow the manual instruction

    FYI this is my code below

    ShoppingCartControlPanel.css

    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Web.UI;
    using Telerik.Framework.Web;
    using Telerik.Web;
     
    using Telerik.Cms.Web.UI.Backend;
    using System.Collections.Generic;
    using Moduleplex.ShoppingCart.WebControls.Admin.Administrator;
    using Moduleplex.ShoppingCart.Configuration;
    using Moduleplex.ShoppingCart.Resources;
     
     
     
    namespace Moduleplex.ShoppingCart.WebControls.Admin
    {
        public class ShoppingCartControlPanel : ProviderControlPanel<ShoppingCartControlPanel>
        {
            #region Constructors
     
            /// <summary>
            /// Initializes a new instance of the <see cref="ShoppingCartControlPanel"/> class.
            /// </summary>
     
            public ShoppingCartControlPanel()
                : base(false)
            {
            }
            /// <summary>
            /// Initializes a new instance of the <see cref="ShoppingCartControlPanel"/> class.
            /// </summary>
            /// <param name="autoGenerateViewCommands">if set to <c>true</c> [auto generate view commands].</param>
            public ShoppingCartControlPanel(bool autoGenerateViewCommands)
                : base(autoGenerateViewCommands)
            {
            }
            #endregion
     
            #region Properties
     
            /// <summary>
            /// Gets an instance of ShoppingCartManager.
            /// </summary>
            public virtual ShoppingCartManager Manager
            {
                get
                {
                    if (this.manager == null)
                        this.manager = new ShoppingCartManager(this.ProviderName);
                    return this.manager;
                }
            }
     
            /// <summary>
            /// The title of the view.
            /// </summary>
            /// <value></value>
            public override string Title
            {
                get
                {
                    return Messages.ModuleTitle;
                }
                set
                {
                    base.Title = value;
                }
            }
     
            #endregion
     
            #region WebControl Methods
     
            /// <summary>
            /// Restores control-state information from a previous page request that was saved by the System.Web.UI.Control.SaveControlState() method.
            /// </summary>
            /// <param name="savedState">An System.Object that represents the control state to be restored.</param>
            protected override void LoadControlState(object savedState)
            {
                if (savedState != null)
                {
                    object[] state = (object[])savedState;
                    base.LoadControlState(state[0]);
                }
            }
     
            /// <summary>
            /// Saves any server control state changes that have occurred since the time
            /// the page was posted back to the server.
            /// </summary>
            /// <returns>
            /// Returns the server control's current state. If there is no state associated
            /// with the control, this method returns null.
            /// </returns>
            protected override object SaveControlState()
            {
                return new object[] { 
                    base.SaveControlState()
                };
            }
     
            #endregion
     
            #region Control Panel Methods
     
            /// <summary>
            /// Loads configured views.
            /// </summary>
            protected override void CreateViews()
            {
                AddView<AdminView>("Administrator", "Administrator", "Administrator", null, null);
                
            }
     
            /// <summary>
            /// Returns a list of custom Command Panels.
            /// </summary>
            /// <param name="viewMode">Specifies the current View Mode</param>
            /// <returns>A list of command panels containing the defined commands for the current View Mode.</returns>
            protected override void CreateCustomCommandPanels(string viewMode, List<ICommandPanel> list)
            {
                list.Add(new ShoppingCartCommandPanel(this));
            }
     
            /// <summary>
            /// Returns the name of the default data provider for the module.
            /// Default data provider is used when no current provider is selected.
            /// The default implementation returns empty string.
            /// </summary>
            /// <returns>A string representing the name of the default data provider for the module.</returns>
            protected override string GetDefaultProviderName()
            {
                return ConfigurationHelper.Handler.DefaultProvider;
            }
     
            /// <summary>
            /// Refreshes the control hierarchy of the control
            /// </summary>
            /// <remarks>
            /// Recreates the controls' child controls.
            /// </remarks>
            public override void Refresh()
            {
                base.Refresh();
                this.manager = null;
            }
     
            #endregion
     
            #region Private Fields
     
            private ShoppingCartManager manager;
     
            #endregion
        }
    }

    ShoppingCartCommandPanel.css
    using System;
    using System.Reflection;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Cms.Web.UI;
    using Telerik.Framework.Web;
    using Telerik.Web;
    using Telerik.Web.UI;
     
    using Moduleplex.ShoppingCart.Interfaces;
    using Moduleplex.ShoppingCart.Data;
    using Moduleplex.ShoppingCart.WebControls.Admin.Administrator;
     
     
    namespace Moduleplex.ShoppingCart.WebControls.Admin
    {
        /// <summary>
        /// Represents ShoppingCart module command panel. It is used to manage Products, Shipping, Store
        /// navigation of the admin part of ShoppingCart module
        /// </summary>
        public class ShoppingCartCommandPanel : ViewModeControl<ShoppingCartControlPanel>, ICommandPanel
        {
            #region Constructor
     
            /// <summary>
            /// Initializes a new instance of the <see cref="ShoppingCartCommandPanel"/> class.
            /// </summary>
            /// <param name="ctrlPnl">The CTRL PNL.</param>
            public ShoppingCartCommandPanel(IControlPanel ctrlPnl)
            {
                controlPanel = ctrlPnl;
            }
     
            #endregion
     
            #region Properties
     
            /// <summary>
            /// Gets or sets the path to a custom layout template for the control.
            /// </summary>
            [WebSysTemplate(layoutTemplateName,"CommandPanelLayoutTemplate","/ShoppingCart/",false,"2010-05-15")]
                
            public override string LayoutTemplatePath
            {
                get
                {
                    return base.LayoutTemplatePath;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
     
            /// <summary>
            /// Gets the name of the embedded layout template. This property must be overridden to provide the path (key) to an embedded resource file.
            /// </summary>
     
            protected override string LayoutTemplateName
            {
                get
                {
                    return layoutTemplateName;
                }
            }
     
             
            /// <summary>
            /// Gets or sets the host of the command panel.
            /// </summary>
            public override ShoppingCartControlPanel Host
            {
                get
                {
                    if (host == null && controlPanel is ShoppingCartControlPanel)
                        host = (ShoppingCartControlPanel)controlPanel;
                    return host;
                }
                set
                {
                    host = value;
                }
            }
     
            /// <summary>
            /// Gets an instance of Manager.
            /// </summary>
            protected ShoppingCartManager Manager
            {
                get
                {
                    return Host.Manager;
                }
            }
     
            #endregion
     
            #region Control references
     
            /// <summary>
            /// Gets the function PanelBar.
            /// </summary>
            /// <value>The function PanelBar.</value>
            protected virtual RadPanelBar RpbFunction
            {
                get
                {
                    return base.Container.GetControl<RadPanelBar>("rpbFunction", true);
                }
            }
     
            /// <summary>
            /// Gets the Shopping Cart CSS.
            /// </summary>
            /// <value>The Shopping Cart CSS.</value>
            protected virtual CssFileLink ShoppingCartCss
            {
                get
                {
                    return base.Container.GetControl<CssFileLink>("shoppingCartCss", true);
                }
            }
     
            #endregion
     
            #region Methods
     
             /// <summary>
            /// Raises the <see cref="E:System.Web.UI.Control.PreRender"/> event.
            /// </summary>
            /// <param name="e">An <see cref="T:System.EventArgs"/> object that contains the event data.</param>
            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
            }
     
            /// <summary>
            /// Initializes all controls instantiated in the layout container. This method is called at appropriate time for setting initial values and subscribing for events of layout controls.
            /// </summary>
            /// <param name="viewContainer">The control that will host the current view.</param>
            protected override void InitializeControls(Control viewContainer)
            {
                BuildFunction();
            }
     
            private void BuildFunction()
            {
                IList<Function> functionData = new List<Function>();
                IList<Function> readAllFunction = this.Manager.ReadAllFunction();
                foreach (IFunction iFunction in readAllFunction)
                {
                    functionData.Add(new Function(iFunction.Id, iFunction.ParentId, iFunction.Name, iFunction.Description, iFunction.Perms, iFunction.Publish, iFunction.ViewName));
                }
                this.RpbFunction.DataTextField = "Name";
                this.RpbFunction.DataFieldID = "Id";
                this.RpbFunction.DataFieldParentID = "ParentId";
                this.RpbFunction.DataValueField = "ViewName";
                this.RpbFunction.ExpandMode = PanelBarExpandMode.SingleExpandedItem;
                this.RpbFunction.Width = Unit.Pixel(200);
                this.RpbFunction.EnableEmbeddedSkins = true;
                this.RpbFunction.Skin = "Sitefinity";
                this.RpbFunction.DataSource = functionData;
                this.RpbFunction.DataBind();
                this.RpbFunction.ItemClick += new RadPanelBarEventHandler(RpbFunction_ItemClick);
            }
            #endregion
     
            #region Event Handlers
     
            private void RpbFunction_ItemClick(object sender, RadPanelBarEventArgs e)
            {
                if (e.Item.Owner is RadPanelItem)
                {
                    RadPanelItem parentItem = (RadPanelItem)e.Item.Owner;
                    string functionName = parentItem.Text;
                    string functionView = e.Item.Value;
                    switch (functionName)
                    {
                        case "Admin":
                            switch (functionView)
                            {
                                case "ConfigurationView":
                                    NavigateRootViewCommand(typeof(ShoppingCartControlPanel), typeof(AdminView), typeof(ConfigurationView));
                                    break;
                            }
                            break;
                    }
                }
            }
                 
                 
     
             
     
            #endregion
     
            #region ICommandPanel Members
     
            /// <summary>Reference to the control panel tied to the command panel instance.</summary>
            /// <remarks>
            /// This property is used for communication between the command panel and its control
            /// panel.
            /// </remarks>
            /// <example>
            ///     You can refer to <see cref="ICommandPanel">ICommandPanel</see> interface for more
            ///     complicated example implementing the whole
            ///     <see cref="ICommandPanel">ICommandPanel</see> interface.
            /// </example>
            public IControlPanel ControlPanel
            {
                get
                {
                    return controlPanel;
                }
            }
     
            /// <summary>Refreshes the command panel information.</summary>
            /// <requirements>
            /// This method could be used to refresh the command panel information. For example
            /// when there is some change in the ControlPanel which reflects on the information of the
            /// CommandPanel.
            /// </requirements>
            /// <example>
            ///     You can refer to <see cref="ICommandPanel">ICommandPanel</see> interface for more
            ///     complicated example implementing the whole
            ///     <see cref="ICommandPanel">ICommandPanel</see> interface.
            /// </example>
            public void Refresh()
            {
                this.ChildControlsCreated = false;
            }
     
            #endregion
     
            #region Private fields
     
            private IControlPanel controlPanel;
            private ShoppingCartControlPanel host;
     
            #endregion
     
            #region Constants
            /// <summary>
            /// The name of the embedded layout template.
            /// </summary>
            public const string layoutTemplateName = "Moduleplex.ShoppingCart.Resources.ControlTemplates.Backend.CommandPanel.ascx";
             
            #endregion
        }
    }

    AdminView.css
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web.UI;
    using Telerik.Cms.Web.UI;
     
    namespace Moduleplex.ShoppingCart.WebControls.Admin.Administrator
    {
        public class AdminView : ViewModeControl<ShoppingCartControlPanel>
        {  
            #region Methods
     
            /// <summary>
            /// Loads configured views.
            /// </summary>
            protected override void CreateViews()
            {
                AddView<ConfigurationView>("Configuration", "Configuration", "Configuration", null, null);
            }
            #endregion
        }
    }

    ConfigurationView.css
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Telerik.Cms.Web.UI;
    using Moduleplex.ShoppingCart;
     
    namespace Moduleplex.ShoppingCart.WebControls.Admin.Administrator
    {
        public class ConfigurationView : ViewModeControl<AdminView>
        {
            #region Properties
     
            /// <summary>
            /// Gets or sets the path to a custom layout template for the control.
            /// </summary>
            [WebSysTemplate(layoutTemplateName, "ConfigurationViewLayoutTemplate", "/ShoppingCart/", false, "2010-05-15")]
     
            public override string LayoutTemplatePath
            {
                get
                {
                    return base.LayoutTemplatePath;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
             
     
            /// <summary>
            /// Gets the name of the embedded layout template.
            /// </summary>
            protected override string LayoutTemplateName
            {
                get
                {
                    return layoutTemplateName;
                }
            }
            #endregion
     
            #region Constants
     
            /// <summary>
            /// Specifies the embeded template name.
            /// </summary>
            protected const string layoutTemplateName = "Moduleplex.ShoppingCart.Resources.ControlTemplates.Backend.Administrator.ConfigurationView.ascx";
     
            #endregion
        }
    }


    Thanks
    Febry Nastrioman



  2. CafeDelMar
    CafeDelMar avatar
    28 posts
    Registered:
    06 May 2007
    20 Jun 2010
    Link to this post
    Dear Telerik Team

    I found the cause of error message, the first parameter of Addview methode should be null value

    AddView<AdminView>("Administrator", "Administrator", "Administrator", null, null);
    AddView<ConfigurationView>("Configuration", "Configuration", "Configuration", null, null);

    should be

    AddView<AdminView>(null, "Administrator", "Administrator", null, null);
    AddView<ConfigurationView>(null, "Configuration", "Configuration", null, null);


    Thanks
    Febry Nastrioman
2 posts, 0 answered