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

Forums / Developing with Sitefinity / Create a Custom Area in a pluggable Module

Create a Custom Area in a pluggable Module

4 posts, 0 answered
  1. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    25 Nov 2009
    Link to this post
    I have been working on a pluggable module, and I want to build an area where I can administer categories (these are not the same as the general sitefinity categories, but custom ones). I tried to create a new control that implemented a template, but I keep getting the follwoing error:

    Server Error in '/Sitefinity' Application. 
    -------------------------------------------------------------------------------- 
     
    The ViewMode "TestControl" is not defined for this control.  
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.  
     
    Exception Details: System.ArgumentException: The ViewMode "TestControl" is not defined for this control. 
     
    Source Error:  
     
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.   
     
    Stack Trace:  
     
     
    [ArgumentException: The ViewMode "TestControl" is not defined for this control.] 
       Telerik.Cms.Web.UI.ViewModeControl`1.get_CurrentView() +146 
       Telerik.Cms.Web.UI.ViewModeControl`1.LoadCurrentView(Control owner) +25 
       Telerik.Cms.Web.UI.ViewModeControl`1.InitializeControls(Control viewContainer) +42 
       Telerik.Cms.Web.UI.ViewModeControl`1.CreateChildControls() +101 
       System.Web.UI.Control.EnsureChildControls() +87 
       System.Web.UI.Control.PreRenderRecursiveInternal() +44 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Control.PreRenderRecursiveInternal() +171 
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842 
     
      
     
     
    -------------------------------------------------------------------------------- 
    Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082  

    The code for the class that drives my control is here:
    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Text; 
    using Telerik.Cms.Web.UI; 
    using System.Web.UI; 
     
    namespace Projects.WebControls.Admin 
        public class TestControl<THost> : ViewModeControl<THost> where THost : ProjectItemsView 
        { 
            private const string TemplateName = "Projects.Resources.ControlTemplates.Backend.TestControl.ascx"
     
            private IProject project; 
            
            #region Properties 
     
             
     
            [WebSysTemplate(TemplateName, "TestControl_Template_Desc""/Projects/"false"2009-06-10")] 
            public override string LayoutTemplatePath 
            { 
                get 
                { 
                    return base.LayoutTemplatePath; 
                } 
                set 
                { 
                    base.LayoutTemplatePath = value; 
                } 
            } 
     
            protected override string LayoutTemplateName 
            { 
                get 
                { 
                    return TemplateName; 
                } 
            } 
             
     
            public virtual ProjectsManager Manager 
            { 
                get 
                { 
                    return this.Host.Manager; 
                } 
            } 
     
            public virtual string ProviderName 
            { 
                get 
                { 
                    return this.Manager.Provider.Name; 
                } 
            } 
            #endregion 
            #region Overriden methods 
     
            protected override void InitializeControls(Control viewContainer) 
            { 
                base.InitializeControls(viewContainer); 
                CreateProjectEditorView(); 
            } 
     
            protected override string AdditionalTemplateKey 
            { 
                get 
                { 
                    return this.Host.Manager.Provider.Name; 
                } 
            } 
            #endregion 
            #region Methods 
     
            protected virtual void CreateProjectEditorView() 
            { 
                // defines the behavior of JobEditor button 
                //this.ProjectEditorControl.ProviderName = this.ProviderName; 
                //if (!IsNewItem()) 
                //{ 
                //    this.ProjectEditorControl.ProjectID = this.DataItemId; 
                //} 
                //this.ProjectEditorControl.CancelUrl = CreateHostViewCommand<ProjectItemsList<THost>>(); 
                //this.ProjectEditorControl.Saved += new EventHandler<EventArgs>(ProjectEditorControl_Saved); 
     
                // defines the behavior of BackButton 
                //this.BackButton.NavigateUrl = CreateHostViewCommand<ProjectItemsList<THost>>(); 
            } 
            
            #endregion 
        } 
     
     

    and my frontend is here:

    <%@ Control Language="C#" ClassName="TestControl" %> 
     
    <script runat="server"
     
    </script> 
    this is it 

    Can someone point out to me whats going wrong here? thanks
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    26 Nov 2009
    Link to this post
    Hello Travis,

    Thank you for using our services.

    I do not see the creation of the child views of the view mode control. You should add an override to the the CreateViews control where you will add the child views that your control will have. You are supposed to add the child views in this method:
    /// Loads configured views.
           /// </summary>
           protected override void CreateViews()
           {
               AddView<ProductsItemListView>("ProductsItemListView", "ProductsItemListView_Title", "ProductsItemListView_Description", null, Messages.ResourceManager);
               AddView<ProductEditView>("ProductEditView", "ProductEditView_Title", "ProductEditView_Description", null, Messages.ResourceManager);
               AddView<ProductHistoryView>("ProductHistoryView", "ProductHistoryView_Title", "ProductHistoryView_Description", null, Messages.ResourceManager);
               AddView<ProductNewView>("ProductNewView", "ProductNewView_Title", "ProductNewView_Description", null, Messages.ResourceManager);
               AddView<ProductPreviewView>("ProductPreviewView", "ProductPreviewView_Title", "ProductPreviewView_Description", null, Messages.ResourceManager);
           }


    Sincerely yours,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    05 Jan 2010
    Link to this post
    So, I got my TestControl URL working, http://localhost:1923/Sitefinity/Sitefinity/Admin/Modules.aspx?module=Projects&route=ControlPanel.TestControl, however, I am now greeted with an error message.
    Invalid resource name (Projects.Resources.ControlTemplates.Backend.TestControl.ascx) for assembly (Projects, Version=1.0.0.0, Culture=neutralPublicKeyToken=null) or empty template. 
    This seems odd to me because if I simply change the name of the ascx file its pointing to (to ProjectItemEdit, for example) it loads up the ProjectItemEdit template. In this case the two templates (ProjectItemEdit.ascx and TestControl.ascx) are both within the same directory, and my TestControl.ascx file is not empty, so i'm a bit confused as to why it's not loading.
  4. Travis
    Travis avatar
    86 posts
    Registered:
    15 Oct 2008
    05 Jan 2010
    Link to this post
    Alright, the reason it couldn't find it was because the ascx file was not set to be an embedded resource. Got it working now.
Register for webinar
4 posts, 0 answered