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

Forums / Developing with Sitefinity / Unable to cast object of type 'ASP.usercontrols_custommodule_commandpanel_ascx' to type 'Telerik.IControlPanelCommand'.

Unable to cast object of type 'ASP.usercontrols_custommodule_commandpanel_ascx' to type 'Telerik.IControlPanelCommand'.

5 posts, 0 answered
  1. sarath
    sarath avatar
    24 posts
    Registered:
    24 Jan 2010
    24 Feb 2010
    Link to this post
    Hi,

    I am trying to implement a custom module. I am keeping the all code files in a seperate class library and the usercontrols in the root site. Please see the below.
    I am getting below exception when I try to do the below.
    CustomModule.cs:
    public override IControlPanelCommand[] CreateToolBoxControls(TemplateControl parent)
          {
            return new IControlPanelCommand[] { (IControlPanelCommand)parent.LoadControl("~/UserControls/CustomModule/CommandPanel.ascx") };
          }
    CommandPanel.ascx:
    <%@ Control Language="C#" AutoEventWireup="true" Inherits="CustomModuleLib.UserControls.Admin.CommandPanel" %>
     <h2>
        Custom Module</h2>

    CommandPanel.cs inherits from
    CommandPanel : UserControl, ICommandPanel

    I am getting the below exception:
    Unable to cast object of type 'ASP.usercontrols_custommodule_commandpanel_ascx' to type 'Telerik.IControlPanelCommand'.

    Thanks,
    Sarath
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    24 Feb 2010
    Link to this post
    Hi sarath,

    IControlPanelCommand is obsolete you have to use Telerik.Web.ICommandPanel instead. Please take a look at this post as well - Command Panel: Creating command panel from User Control

    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. sarath
    sarath avatar
    24 posts
    Registered:
    24 Jan 2010
    25 Feb 2010
    Link to this post
    Thank you for your reply. I am following the suggested new approach, now I am getting the below exception for the templates.

    Invalid resource name (CustomModuleLib.Resources.ControlTemplates.CommandPanel.ascx) for assembly (CustomModuleLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) or empty template.

    I manually added the resource and Controltemplates folders and created the .ascx files.

    Regards,
    Sarath
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    25 Feb 2010
    Link to this post
    Hello sarath,

    Please take a look at Page SiteMap inside CommandPanel post where sample code is provided.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. sarath
    sarath avatar
    24 posts
    Registered:
    24 Jan 2010
    25 Feb 2010
    Link to this post
    Thank you. Actually I followed the below article approach...now I am endup with this exception. Please advice.

    http://www.sitefinity.com/blogs/ivan/posts/09-02-26/sample_pluggable_module_contacts_pluggable_module.aspx

      I added the resources, controltemplates folder manually. The below is the sample code....

    BooksModule :

    using System.Collections.Generic;
    using Telerik;
    using Telerik.Web;
    using Samples.Books.WebControls;

    namespace Samples.Books
    {
        public class BooksModule : WebModule
        {
            /// <summary>
            /// Name of the module
            /// </summary>
            public override string Name
            {
                get
                {
                    return "Books";
                }
            }

            /// <summary>
            /// Title of the module
            /// </summary>
            public override string Title
            {
                get
                {
                    return "Books";
                }
            }

            /// <summary>
            /// Module description
            /// </summary>
            public override string Description
            {
                get
                {
                    return "Sample books module";
                }
            }

            /// <summary>
            ///             Gets information for the controls which would be showed in the toolbox when
            ///             editing a page.
            /// </summary>
            /// <value>
            ///             IList generic collection for the IToolBoxItem objects representing the public
            ///             controls.
            /// </value>
            /// <example>
            /// <code>
            ///             /// &lt;summary&gt;
            ///             /// Gets ToolboxItemCollection with all ToolboxItem objects which register the corresponding control for use in the public part of the CMS system.
            ///             /// &lt;/summary&gt;
            ///             public override IList&lt;IToolboxItem&gt; Controls
            ///             {
            ///                 get
            ///                 {
            ///                     return new List&lt;IToolboxItem&gt;(new ToolboxItem[] { new JobListToolboxItem(), new JobListSummaryToolboxItem() });
            ///                 }
            ///             }
            /// </code>
            /// </example>
            /// <remarks>
            ///                 Each module public control should be represented as a IToolboxItem object which
            ///                 contains information for the type of the control it reffers to as well as a title
            ///                 and description information. For more information take a look at the
            ///                 <see cref="T:Telerik.Web.IToolboxItem">IToolBoxItem</see> interface.
            /// </remarks>
            public override IList<IToolboxItem> Controls
            {
                get
                {
                    // no public controls for the sample module
                    return new List<IToolboxItem>();
                }
            }

            /// <summary>
            /// Creates ControlPanel control which is the main container for the module
            /// administration.
            /// </summary>
            /// <param name="parent">Specifies the container in which the ControlPanel control will be
            /// rendered.</param>
            /// <returns>
            /// Returns the ControlPanel control instance which is the main container for the
            /// module administration.
            /// </returns>
            /// <remarks>
            /// The ControPanel control is usually rendered in the right side of the administration
            /// part for a module. It should inherit the
            /// <see cref="T:Telerik.Web.IControlPanel">Telerik.Web.IControlPanel</see> interface.
            /// Usually the ControlPanel controls inherit the
            /// <see cref="T:Telerik.Web.ControlPanelBase">Telerik.Web.ControlPanelBase</see> class
            /// which in its turn inherits the
            /// <see cref="T:Telerik.Web.IControlPanel">Telerik.Web.IControlPanel</see> and provides
            /// basic implementation for the ControlPanel controls.
            /// </remarks>
            /// <example>
            ///     <code lang="CS" title="CreateControlPanel implementation" description="The following example provides sample implementation of the CreateControlPanel method. It simply returns instance of a control which inherits from ControlPanelBase class and IControlPanel respectively">
            /// /// &lt;summary&gt;
            /// /// Creates the ControlPanel object which is rendered on the right side of the screen.
            /// /// &lt;/summary&gt;
            /// /// &lt;returns&gt;Instance of the ControlPanel object of the module.&lt;/returns&gt;
            /// public override System.Web.UI.Control CreateControlPanel(System.Web.UI.TemplateControl parent)
            /// {
            /// return new Telerik.Samples.Jobs.Pluggable.WebControls.ControlPanel();
            /// }
            /// </code>
            /// </example>
            public override System.Web.UI.Control CreateControlPanel(System.Web.UI.TemplateControl parent)
            {
                return new BooksControlPanel();
            }

        }
    }

    BooksCommandPanel :

    using System.Web.UI.WebControls;
    using Telerik.Cms.Web.UI;
    using Telerik.Cms.Web.UI.Backend;
    using Telerik.Web;

    namespace Samples.Books.WebControls
    {
        /// <summary>
        /// Custom control which is used for command panel
        /// </summary>
        public class BooksCommandPanel : ViewModeControl<BooksControlPanel>, ICommandPanel
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="BooksCommandPanel"/> class.
            /// </summary>
            /// <param name="ctrlPnl">The CTRL PNL.</param>
            public BooksCommandPanel(IControlPanel ctrlPnl)
            {
                this.ctrlPnl = ctrlPnl;
            }

            /// <summary>
            /// Gets or sets the path to a custom layout template for the control.
            /// </summary>
            /// <remarks>
            /// We are overriding this property only to add attribute to it. The attribute will be used in future
            /// for the template mapping / exporting tool.
            /// </remarks>
            [WebSysTemplate(BooksCommandPanel.BooksCommandPanelTemplateName,
                "BooksCommandPanelTemplateName_Template_Desc", "/Books/", false, "2000-01-25")]
            public override string LayoutTemplatePath
            {
                get
                {
                    return base.LayoutTemplatePath;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }

            /// <summary>
            /// Gets the name of the embedded layout template. If the control uses layout template this
            /// property must be overridden to provide the path (key) to an embedded resource file.
            /// </summary>
            /// <value>Name of the resource with embedded template</value>
            protected override string LayoutTemplateName
            {
                get
                {
                    return BooksCommandPanel.BooksCommandPanelTemplateName;
                }
            }

            #region Control references

            /// <summary>
            /// Gets all books.
            /// </summary>
            /// <value>All books.</value>
            protected virtual HyperLink AllBooks
            {
                get { return base.Container.GetControl<HyperLink>("allBooks", true); }
            }

            /// <summary>
            /// Gets the sales.
            /// </summary>
            /// <value>The sales.</value>
            protected virtual HyperLink Sales
            {
                get { return base.Container.GetControl<HyperLink>("sales", true); }
            }

            #endregion

            /// <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(System.Web.UI.Control viewContainer)
            {
                base.InitializeControls(viewContainer);

                this.AllBooks.NavigateUrl = CreateRootViewCommand(typeof (BooksControlPanel), typeof (BooksListView));
                this.Sales.NavigateUrl = CreateRootViewCommand(typeof (BooksControlPanel), typeof (BooksSalesView));
            }

            /// <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="T:Telerik.Web.ICommandPanel">ICommandPanel</see> interface for more
            ///                 complicated example implementing the whole
            ///                 <see cref="T:Telerik.Web.ICommandPanel">ICommandPanel</see> interface.
            /// </example>
            public void Refresh()
            {
                this.ChildControlsCreated = false;
            }

            /// <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="T:Telerik.Web.ICommandPanel">ICommandPanel</see> interface for more
            ///                 complicated example implementing the whole
            ///                 <see cref="T:Telerik.Web.ICommandPanel">ICommandPanel</see> interface.
            /// </example>
            public IControlPanel ControlPanel
            {
                get { return this.ctrlPnl; }
            }

            private IControlPanel ctrlPnl;

            private const string BooksCommandPanelTemplateName =
                "Samples.Books.Resources.ControlTemplates.Backend.BooksCommandPanel.ascx";
        }
    }

    BooksControlPanel :

    using Telerik.Cms.Web.UI.Backend;
    using Telerik;

    namespace Samples.Books.WebControls
    {
        /// <summary>
        /// Control panel for the books module
        /// </summary>
        public class BooksControlPanel : ControlPanel<BooksControlPanel>
        {
            /// <summary>
            /// Initializes a new instance of the <see cref="BooksControlPanel"/> class.
            /// </summary>
            /// <remarks>
            /// We are passing false to base constructor indicating that we do not want automatic
            /// command generation, since this feature is not working properly in the beta release
            /// </remarks>
            public BooksControlPanel() : base(false)
            {
                
            }

            /// <summary>
            /// We are overriding the CreateViews and defining the child views of this control.
            /// </summary>
            protected override void CreateViews()
            {
                // adding view which will display list of views - this is also the default view
                AddView<BooksListView>();
                // adding view which is used for adding new books
                AddView<BookInsertView>();
                // adding view which is used for editing existing books
                AddView<BookEditView>();
                // adding view which is used for previewing a book
                AddView<BookPreviewView>();
                // adding view which is used for viewing the sales report
                AddView<BooksSalesView>();
            }

            /// <summary>
            /// Creates the custom command panels.
            /// </summary>
            /// <param name="viewMode">The view mode.</param>
            /// <param name="list">The list.</param>
            protected override void CreateCustomCommandPanels(string viewMode, System.Collections.Generic.List<Telerik.Web.ICommandPanel> list)
            {
                list.Add(new BooksCommandPanel(this));
            }

        }
    }

    BooksListView :
    using Telerik.Cms.Web.UI;
    using Telerik.Web.UI;
    using System.Web.UI.WebControls;

    namespace Samples.Books.WebControls
    {
        /// <summary>
        /// View for displaying list of books
        /// </summary>
        public class BooksListView : ViewModeControl<BooksControlPanel>
        {
            /// <summary>
            /// Gets or sets the path to a custom layout template for the control.
            /// </summary>
            /// <remarks>
            /// We are overriding this property only to add attribute to it. The attribute will be used in future
            /// for the template mapping / exporting tool.
            /// </remarks>
            [WebSysTemplate(BooksListView.BooksListViewTemplateName,
                "BooksListViewTemplateName_Template_Desc", "/Books/", false, "2000-01-25")]
            public override string LayoutTemplatePath
            {
                get
                {
                    return base.LayoutTemplatePath;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }

            /// <summary>
            /// Gets the name of the embedded layout template. If the control uses layout template this
            /// property must be overridden to provide the path (key) to an embedded resource file.
            /// </summary>
            /// <value>Name of the resource with embedded template</value>
            protected override string LayoutTemplateName
            {
                get
                {
                    return BooksListView.BooksListViewTemplateName;
                }
            }

            // we are not using a separate class of container for each control, but rather the one implemented on the
            // base ViewModeControl
            #region Control references

            protected virtual HyperLink CreateNewButton
            {
                get { return base.Container.GetControl<HyperLink>("createNewButton", true); }
            }

            #endregion

            /// <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(System.Web.UI.Control viewContainer)
            {
                base.InitializeControls(viewContainer);

                // notice how we are not initializing templates and containers anymore - all this is now responsility of the
                // base ViewModeControl class

                // when switching from one view to another, we will not use postbacks anymore, but rather
                // a hyperlink. To get the url, all we have to do is call CreateHosViewCommand function
                // of the base class and specify the generic type for the view for which we desire to
                // create the command
                this.CreateNewButton.NavigateUrl = CreateHostViewCommand<BookInsertView>();
            }

            private const string BooksListViewTemplateName = "Samples.Books.Resources.ControlTemplates.Backend.BooksListView.ascx";
        }
    }

    Same approach I followed but i am getting the Invalid resource name (CustomModuleLib.Resources.ControlTemplates.CommandPanel.ascx) for assembly (CustomModuleLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null) or empty template. exception.

    I liked this approach and would like to load the templates as views i.e similar to private const string BooksListViewTemplateName = "Samples.Books.Resources.ControlTemplates.Backend.BooksListView.ascx";

    Please advice.

    Regards,
    Sarath
Register for webinar
5 posts, 0 answered