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

Forums / Developing with Sitefinity / Custom Designer woes

Custom Designer woes

2 posts, 0 answered
  1. Kameron
    Kameron avatar
    9 posts
    Registered:
    07 Nov 2011
    17 Nov 2011
    Link to this post
    Hello,
    So I was able to follow two examples on creating a custom designer control for my widget. It appears when I click on the edit link of the controller. It does not however show the results that are set for the control, nor does it save them. If I make a change to any of the options and hit save, nothing happens and when you edit it again, it does not show the saved values but rather the defaults. Thank you. Kameron

    Here is the jquery I have (VideoEditorDesigner.js):
    Type.registerNamespace("YRMC.Sitefinity.Web.UI");
    YRMC.Sitefinity.Web.UI.VideoEditorTemplate = 
    function (element) {
        YRMC.Sitefinity.Web.UI.VideoEditorTemplate.initializeBase(this, [element]);
    }
      
    YRMC.Sitefinity.Web.UI.VideoEditorTemplate.prototype = {
        initialize: function () {
            YRMC.Sitefinity.Web.UI.VideoEditorTemplate.callBaseMethod(this, 'initialize');
        }, dispose: function () {
            YRMC.Sitefinity.Web.UI.VideoEditorTemplate.callBaseMethod(this, 'dispose');
        },
        refreshUI: function () {
            var controlData = this._propertyEditor.get_control();
            // bind widget properites to designer
            jQuery("#ddSortBy").val(controlData.SortBy);
            jQuery("#ddSortOrder").val(controlData.SortOrder);
            jQuery("#tbFolder").val(controlData.FolderName);
        },
        applyChanges: function () {
            var controlData = this._propertyEditor.get_control();
            // bind designer properties back to widget
            controlData.SortBy = jQuery("#ddSortBy").val();
            controlData.SortOrder = jQuery("#ddSortOrder").val();
            controlData.FolderName = jQuery("#tbFolder").val();
        }
    }
    YRMC.Sitefinity.Web.UI.VideoEditorTemplate.registerClass('YRMC.Sitefinity.Web.UI.VideoEditorTemplate', Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
                    if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

    Here is the designer CS code (VideoEditorTemplate.cs):
    using System;
    using System.Collections;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Collections.Generic;
      
      
    namespace YRMC.Sitefinity.Web.UI
    {
        using Telerik.Sitefinity.Web.UI.ControlDesign;
      
      
        public class VideoEditorTemplate : ControlDesignerBase
        {
            protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
            {
                base.DesignerMode=ControlDesignerModes.Simple;
            }
      
            public override string LayoutTemplatePath
            {
                get
                {
                    return LayoutTemplateReference;
                }
                set
                {
                    base.LayoutTemplatePath = value;
                }
            }
      
            protected override string LayoutTemplateName
            {
                get { return string.Empty; }
            }
      
            public override IEnumerable<ScriptReference> GetScriptReferences()
            {
                // get script collection
                var scripts = base.GetScriptReferences() as List<ScriptReference>;
                if (scripts == null) return base.GetScriptReferences();
                            var assemblyName = this.GetType().Assembly.GetName().ToString();
      
                            scripts.Add(new ScriptReference(_scriptReference, assemblyName));
                return scripts.ToArray();
            }
      
            private string _scriptReference = "YRMC.Sitefinity.VideoEditorDesigner.js";
            private const string LayoutTemplateReference = "~/sfyrmc/YRMC.Sitefinity.Resources.Views.VideoEditorTemplate.ascx";
        }
    }


    Here is a snipit of code from the widget's code (VideoPlaylist.cs):
    namespace YRMC.Sitefinity.Web.UI
    {
        [ControlDesigner(typeof(VideoEditorTemplate))]
        [RequireScriptManager]
        public class VideoPlaylist : SimpleView
        {
              
            #region SitefinityNeeded
            /// <summary>
            /// Variables pulled in from Sitefinity.
            /// Sortorder can be specified by Data or Name of the file.
            /// The Department refers to the folder off of the _rootDirectory. i.e. Education or SkooterShows:YRMCFLVs
            /// The : will get replaced with a forward slash or a back slash, depending on how it will be used
            /// by the application, either as a URL or UNC.
            /// </summary>
            private string sortOrder = "Descending";
            private string folderPath = "Education";
            private string sortBy = "Date";
            public string SortBy { get { return sortBy; } set { sortBy = value; } }
            public string SortOrder { get { return sortOrder; } set { sortOrder = value; } }
            public string FolderName { get { return folderPath; } set { folderPath = value; } }
            private static string _rootDirectory = @"\\yrmc.org\cdn\access\videos\";
      
            protected override string LayoutTemplateName
             {
                 get { return "YRMC.Sitefinity.Resources.Views.VideoPlaylist.ascx"; }
             }


    And here is the ascx of the control(VideoEditorTemplate.ascx):
    <h2>
        Select the required properties.
    </h2>
      
    <p>
        Sort by:
        <asp:DropDownList ID="ddSortBy" runat="server">
            <asp:ListItem Selected="True" Text="File Date" Value="date"/>
            <asp:ListItem Text="File Name" Value="name"/>
        </asp:DropDownList>
        <br />
        Sort order:
        <asp:DropDownList ID="ddSortOrder" runat="server">
            <asp:ListItem Selected="True" Text="Descending" Value="descending" />
            <asp:ListItem Text="Ascending" Value="ascending" />
        </asp:DropDownList>
        <br />
        Folder name: (seperate folder names with /) 
        <asp:TextBox ID="tbFolder" runat="server" ToolTip="i.e: ScooterShows/YRMCFLVs" Text="Education"/>
    </p>



  2. Kameron
    Kameron avatar
    9 posts
    Registered:
    07 Nov 2011
    18 Nov 2011
    Link to this post
    Solved. It was dumb. Removed the runat="server" tag
2 posts, 0 answered