MediaSelector In Control Designer?

Posted by Community Admin on 04-Aug-2018 19:37

MediaSelector In Control Designer?

All Replies

Posted by Community Admin on 19-Apr-2012 00:00

Can anyone point me to an example using the MediaField?  I'm assuming this is what I need to use for a PDF equivelant to the ImageField control. I have a great example of the ImageField from this link, but can't find anything that shows how to do similar for PDFs.

Thanks,
Cory

Posted by Community Admin on 21-Apr-2012 00:00

Hi Cory - 

Here is an example. Can be used for either Documents or Videos, just change "Document" => "Video" below.

Once you've created your files, right click on the ascx and js files, click properties and change them to be  embedded resources.

This will return the GUID of the media file. There are, however, more properties available. Reflect the members in the js file to the console to see them, like so..

1.var selector = this.get_Selector();
2. 
3.for (var m in selector)
4.
5.    console.log(m + ' => ' + selector[m]);
6.

MediaSelectorDesigner.ascx

01.<%@ Control Language="C#" AutoEventWireup="true" %>
02.<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers" TagPrefix="sf" %>
03. 
04.<br />
05. 
06.<div class="document-designer">
07.    <sf:MediaContentSelectorView ID="Selector" runat="server"
08.        ContentType = "Telerik.Sitefinity.Libraries.Model.Document"
09.        ParentType = "Telerik.Sitefinity.Libraries.Model.DocumentLibrary"
10.        LibraryBinderServiceUrl = "~/Sitefinity/Services/Content/DocumentLibraryService.svc/"
11.        MediaContentBinderServiceUrl = "~/Sitefinity/Services/Content/DocumentService.svc/"
12.        MediaContentItemsListDescriptionTemplate = "Telerik.Sitefinity.Resources.Templates.Designers.Libraries.Documents.DocumentItemDescriptionTemplate.htm"
13.        DisplayResizingOptionsControl = "false"
14.        ShowOpenOriginalSizeCheckBox = "false">
15.    </sf:MediaContentSelectorView>
16.</div>

MediaSelectorDesigner.cs

01.using System;
02.using System.Collections.Generic;
03.using System.Data;
04.using System.Linq;
05.using System.Web;
06.using System.Web.UI;
07.using System.Web.UI.HtmlControls;
08.using System.Web.UI.WebControls;
09. 
10.using Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers;
11.using Telerik.Sitefinity.Web.UI;
12.using Telerik.Sitefinity.Web.UI.ControlDesign;
13. 
14.namespace Designers.MediaSelectorDesigner
15.
16.    public class MediaSelectorDesigner : ControlDesignerBase
17.    
18.        protected override void InitializeControls(GenericContainer container)
19.        
20.            this.PropertyEditor.HideAdvancedMode = true;
21.        
22. 
23.        protected override void OnPreRender(EventArgs e)
24.        
25.            base.OnPreRender(e);
26.        
27. 
28.        protected override string LayoutTemplateName
29.        
30.            get
31.            
32.                return "Designers.MediaSelectorDesigner.ascx";
33.            
34.        
35. 
36.        public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
37.        
38.            var scriptDescriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
39.            var desc = (ScriptControlDescriptor)scriptDescriptors.Last();
40. 
41.            desc.AddComponentProperty("Selector", this.Selector.ClientID);
42. 
43.            return new[] desc ;
44.        
45. 
46.        public override IEnumerable<ScriptReference> GetScriptReferences()
47.        
48.            var res = new List<ScriptReference>(base.GetScriptReferences());
49.            var assemblyName = this.GetType().Assembly.GetName().ToString();
50. 
51.            res.Add(new ScriptReference("Designers.MediaSelectorDesigner.js", assemblyName));
52. 
53.            return res.ToArray();
54.        
55. 
56.        # region Controls
57. 
58.        protected MediaContentSelectorView Selector
59.        
60.            get
61.            
62.                return this.Container.GetControl<MediaContentSelectorView>("Selector", true);
63.            
64.        
65. 
66.        # endregion
67.    
68.

MediaSelectorDesigner.js

01.Type.registerNamespace("Designers");
02. 
03.Designers.MediaSelectorDesigner = function (element)
04.
05.    Designers.MediaSelectorDesigner.initializeBase(this, [element]);
06. 
07.    this._Selector = null;
08.
09. 
10.Designers.MediaSelectorDesigner.prototype =
11.
12.    initialize: function ()
13.    
14.        Designers.MediaSelectorDesigner.callBaseMethod(this, 'initialize');
15.    ,
16. 
17.    dispose: function ()
18.    
19.        Designers.MediaSelectorDesigner.callBaseMethod(this, 'dispose');
20.    ,
21. 
22.    refreshUI: function ()
23.    
24.        var controlData = this.get_controlData();
25.    ,
26. 
27.    applyChanges: function ()
28.    
29.        var controlData = this.get_controlData();
30.        var selectedMedia = this.get_Selector().get_selectedItem();
31. 
32.        controlData.MediaId = selectedMedia.Id;
33.    ,
34. 
35.    get_controlData: function ()
36.    
37.        return this.get_propertyEditor().get_control();
38.    ,
39. 
40.    get_propertyEditor: function ()
41.    
42.        return this._propertyEditor;
43.    ,
44. 
45.    get_Selector: function ()
46.    
47.        return this._Selector;
48.    ,
49. 
50.    set_Selector: function (value)
51.    
52.        this._Selector = value;
53.    
54.
55. 
56.Designers.MediaSelectorDesigner.registerClass('Designers.MediaSelectorDesigner', Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
57. 
58.if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

MediaSelector.cs
This is your control that you will register in Sitefinity -> Adminsitration -> Settings -> Advanced -> Toolbox ...

01.using System;
02.using System.Collections;
03.using System.Collections.Generic;
04.using System.Linq;
05.using System.Web;
06.using System.Web.Script.Serialization;
07.using System.Web.UI;
08.using System.Web.UI.HtmlControls;
09.using System.Web.UI.WebControls;
10. 
11.using Telerik.Sitefinity;
12.using Telerik.Sitefinity.GenericContent.Model;
13.using Telerik.Sitefinity.Model;
14.using Telerik.Sitefinity.Modules.Pages;
15.using Telerik.Sitefinity.Pages.Model;
16.using Telerik.Sitefinity.Web;
17.using Telerik.Sitefinity.Web.UI;
18.using Telerik.Sitefinity.Web.UI.ControlDesign;
19. 
20.namespace Controls
21.
22.    [ControlDesigner(typeof(MediaSelectorDesigner)), PropertyEditorTitle("Select Media")]
23.    public partial class MediaSelector : SimpleView
24.    
25.        public Guid MediaId
26.        
27.            get;
28.            set;
29.        
30. 
31.        protected override string LayoutTemplateName
32.        
33.            get return "Controls.MediaSelector.ascx";
34.        
35. 
36.        protected override void InitializeControls(GenericContainer container)
37.        
38. 
39.        
40. 
41.        protected override void OnPreRender(EventArgs e)
42.        
43.            base.OnPreRender(e);
44. 
45.            // add your logic here...
46.            // use the fluent api to pass in the ID and retrieve a Document or Video
47.        
48. 
49.        # region Controls
50. 
51.        // add your controls here...
52. 
53.        protected Literal NoMedia
54.        
55.            get return this.Container.GetControl<Literal>("NoMedia", true);
56.        
57. 
58.        # endregion
59.    
60.

MediaSelector.ascx

01.<%@ Control Language="C#" AutoEventWireup="true" %>
02. 
03.<!--
04. 
05.Just an example...
06. 
07.-->
08. 
09.<div class="media-selector">
10.    <asp:Literal ID="NoMedia" runat="server" />
11.</div>

Will look similar to the Image Selector you've already implemented.

Hope this helps you out!

Cheers,
Josh

Posted by Community Admin on 26-Apr-2012 00:00

Hi, I'm using your code as an example. I'm getting an error that says "already contains a definition for NoMedia", it is happening in ascx.designer.cs.

control.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="control.ascx.cs" Inherits="SitefinityWebApp.controls.PDFs.PDFCTA.control" %>

<div class="fact-sheet left">
    <asp:HyperLink ID="PDFLinkURL1" runat="server" Target="_blank"><asp:Image ID="PDFImg" runat="server" /></asp:HyperLink>
    <asp:HyperLink ID="PDFLinkURL2" runat="server" Target="_blank"></asp:HyperLink>
    <asp:HyperLink ID="PDFLinkURL3" runat="server" CssClass="pdf-link" Target="_blank"></asp:HyperLink>
    <div class="media-selector">
        <asp:Literal ID="NoMedia" runat="server"/>
    </div>

</div>

control.ascx.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Script.Serialization;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Web;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;

using Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers;

namespace SitefinityWebApp.controls.PDFs.PDFCTA

    [ControlDesigner(typeof(designer)),PropertyEditorTitle("Select Media")]
    public partial class control : ControlDesignerBase
   
        private string _PDFUrl;
        private string _PDFName;
        private string _PDFDetails;
        public Guid MediaId
       
            get;
            set;
       
        public string PdfUrl
       
            get return _PDFUrl;
            set _PDFUrl = value;
       
        public string PdfName
       
            get return _PDFName;
            set _PDFName = value;
       
        public string PdfDetails
       
            get return _PDFDetails;
            set _PDFDetails = value;
       

        protected override string LayoutTemplateName
       
            get return "controls.PDFs.PDFCTA.designer.ascx";
       
        protected override void InitializeControls(GenericContainer container)
       
           
       
        protected override void OnPreRender(EventArgs e)
       
            base.OnPreRender(e);
   
            // add your logic here...
            // use the fluent api to pass in the ID and retrieve a Document or Video
       

        protected void Page_Load(object sender, EventArgs e)
       
            if(!_PDFUrl.IsNullOrEmpty())
           
                PDFImg.ImageUrl = "~/App_Themes/Microsite/global/images/pdf-cover-fact-sheets.jpg";

                PDFLinkURL1.NavigateUrl = _PDFUrl.Trim();
                PDFLinkURL2.NavigateUrl = _PDFUrl.Trim();
                PDFLinkURL3.NavigateUrl = _PDFUrl.Trim();
           
            if(!_PDFName.IsNullOrEmpty())
           
                //PDFTitle.Text = _PDFName;
                PDFLinkURL2.Text = "<h2 class='left'>" + _PDFName.Trim() + "</h2>";
                PDFLinkURL1.ToolTip = _PDFName.Trim();
                PDFLinkURL2.ToolTip = _PDFName.Trim();
                PDFLinkURL3.ToolTip = _PDFName.Trim();
                PDFImg.AlternateText = _PDFName;
           
            if(!_PDFDetails.IsNullOrEmpty())
           
                PDFLinkURL3.Text = _PDFDetails.Trim();
           
       
        # region Controls
   
        // add your controls here...

        protected Literal NoMedia
       
            get return this.Container.GetControl<Literal>("NoMedia", true);
       
   
        # endregion

   


control.ascx.designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace SitefinityWebApp.controls.PDFs.PDFCTA
   
   
    public partial class control
       
        /// <summary>
        /// PDFLinkURL1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.HyperLink PDFLinkURL1;
       
        /// <summary>
        /// PDFImg control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Image PDFImg;
       
        /// <summary>
        /// PDFLinkURL2 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.HyperLink PDFLinkURL2;
       
        /// <summary>
        /// PDFLinkURL3 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.HyperLink PDFLinkURL3;
       
        /// <summary>
        /// NoMedia control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Literal NoMedia;
   


Thanks for your help,
Jon

Posted by Community Admin on 26-Apr-2012 00:00

Hi Jon - 

No worries. Delete the designer file and remove the code-behind and inherit attributes from the top of your ascx control. They are not needed as the actual class is your control and the ascx file is your template to that control which is parsed via the LayoutTemplateName.


Cheers,
Josh

Posted by Community Admin on 26-Apr-2012 00:00

Sorry I think I've written this wrong for what I'm trying to do.

What I'm trying to accomplish in the widget is an icon, a title, and a description linking to the same PDF.  The name of the file for the PDF is the title. I guess I've mucked up the code for the user control here.  I assume I would still need these two files to pass the data for the IDs properly to the widget?

I am still getting the error "already contains the definition for..." for the 3 IDs PDFLink1, PDFLink2, and PDFLink3.

Here is the code again:
control.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="control.ascx.cs" Inherits="SitefinityWebApp.controls.PDFs.PDFCTA.control" %>

<div class="fact-sheet left">
    <asp:Hyperlink ID="PDFLinkURL1" runat="server" Target="_blank"><asp:Image ID="PDFImg" runat="server" /></asp:Hyperlink>
    <asp:Hyperlink ID="PDFLinkURL2" runat="server" Target="_blank"></asp:Hyperlink>
    <asp:Hyperlink ID="PDFLinkURL3" runat="server" CssClass="pdf-link" Target="_blank"></asp:Hyperlink>

</div>

control.ascx.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Script.Serialization;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Web;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity.GenericContent.Model;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity.Modules.Pages;
using Telerik.Sitefinity.Pages.Model;

using Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers;


namespace SitefinityWebApp.controls.PDFs.PDFCTA

    [ControlDesigner(typeof(designer)),PropertyEditorTitle("Select Media")]
    public partial class control : ControlDesignerBase
   
        private string _PDFUrl;
        private string _PDFName;
        private string _PDFDetails;
        public Guid MediaId
       
            get;
            set;
       
        public string PdfUrl
       
            get return _PDFUrl;
            set _PDFUrl = value;
       
        public string PdfName
       
            get return _PDFName;
            set _PDFName = value;
       
        public string PdfDetails
       
            get return _PDFDetails;
            set _PDFDetails = value;
       

        protected override string LayoutTemplateName
       
            get return "controls.PDFs.PDFCTA.designer.ascx";
       
        protected override void InitializeControls(GenericContainer container)
       
           
       
        protected override void OnPreRender(EventArgs e)
       
            base.OnPreRender(e);
   
            // add your logic here...
            // use the fluent api to pass in the ID and retrieve a Document or Video
       

        protected void Page_Load(object sender, EventArgs e)
       
            if(!_PDFUrl.IsNullOrEmpty())
           
                PDFImg.ImageUrl = "~/App_Themes/Microsite/global/images/pdf-cover-fact-sheets.jpg";

           
            if(!_PDFName.IsNullOrEmpty())
           
                //PDFTitle.Text = _PDFName;
                //PDFLinkURL2.Text = "<h2 class='left'>" + _PDFName.Trim() + "</h2>";
                //PDFLinkURL1.ToolTip = _PDFName.Trim();
                //PDFLinkURL2.ToolTip = _PDFName.Trim();
                //PDFLinkURL3.ToolTip = _PDFName.Trim();
                PDFImg.AlternateText = _PDFName;
           
            if(!_PDFDetails.IsNullOrEmpty())
           
                //PDFLinkURL3.Text = _PDFDetails.Trim();
           
       
        # region Controls
   
        // add your controls here...

        protected HyperLink PDFLinkURL1
       
            get return this.Container.GetControl<HyperLink>("PDFLinkURL1", true);
       

        protected HyperLink PDFLinkURL2
       
            get return this.Container.GetControl<HyperLink>("PDFLinkURL2", true);
       

        protected HyperLink PDFLinkURL3
       
            get return this.Container.GetControl<HyperLink>("PDFLinkURL3", true);
       
        # endregion

   


control.ascx.designer.cs
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace SitefinityWebApp.controls.PDFs.PDFCTA
   
   
    public partial class control
       
        /// <summary>
        /// PDFLinkURL1 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.HyperLink PDFLinkURL1;
       
        /// <summary>
        /// PDFImg control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.Image PDFImg;
       
        /// <summary>
        /// PDFLinkURL2 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.HyperLink PDFLinkURL2;
       
        /// <summary>
        /// PDFLinkURL3 control.
        /// </summary>
        /// <remarks>
        /// Auto-generated field.
        /// To modify move field declaration from designer file to code-behind file.
        /// </remarks>
        protected global::System.Web.UI.WebControls.HyperLink PDFLinkURL3;
   


designer.ascx
<%@ Control Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers" TagPrefix="sf" %>

<div>
    <label for="txtName">Name:</label><br />
    <input type="text" id="txtName" />
</div>

<div>
    <label for="txtDetails">Details:</label><br />
    <input type="text" id="txtDetails" />
</div>
<div class="embedDocument-designer">
    <sf:MediaContentSelectorView ID="Selector" runat="server" ContentType= "Telerik.Sitefinity.Libraries.Model.Document" ParentType= "Telerik.Sitefinity.Libraries.Model.DocumentLibrary" LibraryBinderServiceUrl= "~/Sitefinity/Services/Content/DocumentLibraryService.svc/" MediaContentBinderServiceUrl= "~/Sitefinity/Services/Content/DocumentService.svc/" MediaContentItemsListDescriptionTemplate= "Telerik.Sitefinity.Resources.Templates.Designers.Libraries.Documents.DocumentItemDescriptionTemplate.htm" DisplayResizingOptionsControl= "false" ShowOpenOriginalSizeCheckBox= "false">
    </sf:MediaContentSelectorView>
</div>

designer.js
Type.registerNamespace("SitefinityWebApp.controls.PDFs.PDFCTA.control");

SitefinityWebApp.controls.PDFs.PDFCTA.designer = function (element)
    SitefinityWebApp.controls.PDFs.PDFCTA.designer.initializeBase(this, [element]);
    this._Selector = null;


SitefinityWebApp.controls.PDFs.PDFCTA.designer.prototype =
    initialize: function ()
        SitefinityWebApp.controls.PDFs.PDFCTA.designer.callBaseMethod(this, 'initialize');
    ,
    dispose: function ()
        SitefinityWebApp.controls.PDFs.PDFCTA.designer.callBaseMethod(this, 'dispose');
    ,
    refreshUI: function ()
        var controlData = this._propertyEditor.get_control();

        // bind widget properites to designer
        jQuery("#txtName").val(controlData.PdfName);
        jQuery("#txtUrl").val(controlData.PdfUrl);
        jQuery("#txtDetails").val(controlData.PdfDetails);

    ,
    applyChanges: function ()

        var controlData = this._propertyEditor.get_control();
        var selectedMedia = this.get_Selector().get_selectedItem();

        // bind designer properties back to widget
        controlData.Name = jQuery("#txtName").val();
        controlData.PdfUrl = jQuery("#txtUrl").val();
        controlData.PdfDetails = jQuery("#txtDetails").val();
        controlData.MediaId = selectedMedia.Id;

    ,
    get_propertyEditor: function ()
   
        return this._propertyEditor;
    ,
    get_Selector: function ()
   
        return this._Selector;
    ,
    set_Selector: function (value)
   
        this._Selector = value;
   


SitefinityWebApp.controls.PDFs.PDFCTA.designer.registerClass('SitefinityWebApp.controls.PDFs.PDFCTA.designer', Telerik.Sitefinity.Web.UI.ControlDesign.ControlDesignerBase);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

designer.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers;


namespace SitefinityWebApp.controls.PDFs.PDFCTA

    public class designer : ControlDesignerBase
   
        protected override void InitializeControls(Telerik.Sitefinity.Web.UI.GenericContainer container)
       
            base.DesignerMode = ControlDesignerModes.Simple;
            this.PropertyEditor.HideAdvancedMode = true;
       
        protected override void OnPreRender(EventArgs e)
       
            base.OnPreRender(e);
       

        public override string LayoutTemplatePath
       
            get
           
                return _layoutTemplatePath;
           
            set
           
                _layoutTemplatePath = value;
           
       

        protected override string LayoutTemplateName
       
            get return string.Empty;
       
        public override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
       
            var scriptDescriptors = new List<ScriptDescriptor>(base.GetScriptDescriptors());
            var desc = (ScriptControlDescriptor)scriptDescriptors.Last();
           
            desc.AddComponentProperty("Selector", this.Selector.ClientID);
            return new[] desc ;
           
       

        public override IEnumerable<ScriptReference> GetScriptReferences()
       
            // get script collection
            var assemblyName = this.GetType().Assembly.GetName().ToString();
            var res = new List<ScriptReference>(base.GetScriptReferences());
            var scripts = base.GetScriptReferences() as List<ScriptReference>;
            if (scripts == null) return base.GetScriptReferences();
            res.Add(new ScriptReference("controls.PDFs.PDFCTA.designer.js", assemblyName));
            scripts.Add(new ScriptReference(_scriptReference));
            scripts.Concat(res);
            return scripts;
       
        # region Controls

            protected MediaContentSelectorView Selector
           
                get
               
                    return this.Container.GetControl<MediaContentSelectorView>("Selector", true);
               
           
   
        # endregion


        private string _layoutTemplatePath = "~/controls/PDFs/PDFCTA/designer.ascx";
        private string _scriptReference = "~/controls/PDFs/PDFCTA/designer.js";
   


Thanks again for your help

Posted by Community Admin on 26-Apr-2012 00:00

Sorry brainfart, the 3 IDs are PDFLinkURL1, PDFLinkURL2, PDFLinkURL3

Posted by Community Admin on 26-Apr-2012 00:00

Hi Jon - 

Delete the designer.ascx.cs file and remove the following from the top of your control:

CodeBehind="control.ascx.cs" Inherits="SitefinityWebApp.controls.PDFs.PDFCTA.control"

In your designer js file,  change:

Type.registerNamespace("SitefinityWebApp.controls.PDFs.PDFCTA.control");

to

Type.registerNamespace("SitefinityWebApp.controls.PDFs.PDFCTA");

You're trying to register the control rather than the namespace. 

You also don't need private variables for your getters/setters. get; set; will work like so...

        public string PdfUrl
       
            get;
            set;
       

Next, these two are redundant:

base.DesignerMode = ControlDesignerModes.Simple; // starts in simple mode
this.PropertyEditor.HideAdvancedMode = true; // hides simple mode (i.e. the button goes away), thus starting in simple mode

If you won't want users switching between simple and advanced modes, the following is sufficient:

this.PropertyEditor.HideAdvancedMode = true;

Next, change your file references from:

        private string _layoutTemplatePath = "~/controls/PDFs/PDFCTA/designer.ascx";
        private string _scriptReference = "~/controls/PDFs/PDFCTA/designer.js";

to:

        private string _layoutTemplatePath = "SitefinityWebApp.controls.PDFs.PDFCTA.designer.ascx";
        private string _scriptReference = "SitefinityWebApp.controls.PDFs.PDFCTA.designer.js";

Remove Page_Load from your control and place your logic in either the InitializeControls or OnPreRender methods.

Try these and let me know if it works for ya.

Also, make sure your designer (ascx), control (ascx) and js are all embedded resources. Right click on the files -> Properties -> Build Action.


Cheers,
Josh

This thread is closed