Control designer with ascx template requires javascript file

Posted by Community Admin on 03-Aug-2018 23:17

Control designer with ascx template requires javascript file to work?

All Replies

Posted by Community Admin on 29-Oct-2010 00:00

Hello,

recently I've played with controls and designers and it seems, that without javascript file for designer (which registers appropriate javascript namespace with the name of designer like in NewsRotator sample) I get javascript exception in

Sys.Application.add_init(function()
$create( <designer type name> , null, null, "propertyEditor":"ctl05", $get("ctl05_ctl00_ctl00"));

The designer uses ascx template via LayoutTemplateName.

Is this by design behavior or a bug?

Best reagards,
Robert 

Posted by Community Admin on 31-Oct-2010 00:00

Hi Robert,

Could you show the control and the script you use for your custom control designer?

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

Posted by Community Admin on 01-Nov-2010 00:00

Hi Ivan,


ok here is the control:

[RequireScriptManager]
    [ControlDesigner(typeof(RotatorDesigner)), PropertyEditorTitle(typeof(Labels), "Change")]
    public class Rotator : SimpleView
    
        #region Fields
 
        private Unit width = new Unit(100, UnitType.Pixel);
        private Unit height = new Unit(50, UnitType.Pixel);
        private Color textColor = Color.White;
        private Guid albumGuid = Guid.Empty;
         
        [Browsable(true)]
        public Unit Width
        
            get return this.width;
            set this.width = value;
        
 
        [Browsable(true)]
        public Unit Height
        
            get return this.height;
            set this.height = value;
        
 
        [Browsable(true)]
        public Color TextColor
        
            get return this.textColor;
            set this.textColor = value;
        
 
        [Browsable(true)]
        public Guid AlbumGuid
        
            get return this.albumGuid;
            set this.albumGuid = value;
        
 
        #endregion
 
        #region Controls
 
        protected virtual RadRotator RotatorCtrl
        
            get return this.Container.GetControl<RadRotator>("rotator1", true);
        
 
        #endregion
 
        protected override void InitializeControls(GenericContainer container)
        
            this.RotatorCtrl.Width = Width;
            this.RotatorCtrl.Height = Height;
 
            if (AlbumGuid.Equals(Guid.Empty) == false)
            
                LibrariesManager man = new LibrariesManager();
                var album = man.GetAlbums().Where(a => a.Id.Equals(AlbumGuid)).SingleOrDefault();
 
                if (album != null)
                
                    this.RotatorCtrl.ItemTemplate = new RotatorTemplate(this);
                    this.RotatorCtrl.OnClientItemShowing = "rotatorItemShowing";
                    this.RotatorCtrl.OnClientItemShown = "rotatorItemShown";
                    this.RotatorCtrl.ItemHeight = new Unit(this.Height.Value, UnitType.Pixel);
                    this.RotatorCtrl.ItemWidth = new Unit(this.Width.Value, UnitType.Pixel);
                    this.RotatorCtrl.RotatorType = RotatorType.SlideShow;
                    this.RotatorCtrl.SlideShowAnimation.Type = Telerik.Web.UI.Rotator.AnimationType.Fade;
                    this.RotatorCtrl.PauseOnMouseOver = false;
 
                    this.RotatorCtrl.DataSource = from i in album.Images
                                                  select new i.MediaUrl, Text = i.AlternativeText ;
                    this.RotatorCtrl.DataBind();
                
            
            else
            
                Label lab = new Label();
                lab.Text = "No Album selected.";
                this.Container.Controls.Add(lab);
            
        
 
        protected override void OnPreRender(EventArgs e)
        
            //register client stuff
            this.Page.ClientScript.RegisterClientScriptResource(this.GetType(), "ITOne.Sitefinity.Controls.Rotator.Resources.Rotator.css");
            this.Page.ClientScript.RegisterClientScriptResource(this.GetType(), "ITOne.Sitefinity.Controls.Rotator.Resources.Rotator.js");
 
            base.OnPreRender(e);
        
 
        protected override Type ResourcesAssemblyInfo
        
            get
            
                return this.GetType();
            
        
 
        protected override string LayoutTemplateName
        
            get return "ITOne.Sitefinity.Controls.Rotator.Resources.Rotator.ascx";
        
    

The designer:

public class RotatorDesigner : ControlDesignerBase
    
        #region Controls
 
        protected virtual RadComboBox Combo
        
            get return this.Container.GetControl<RadComboBox>("combo1", true);
        
 
        #endregion
 
        protected override void InitializeControls(GenericContainer container)
        
            this.DesignerMode = ControlDesignerModes.Simple;
 
            //populate combo with libraries
/*          using (var facade = App.WorkWith())
            
                var libs = facade.Documents().Get();
                this.Combo.DataTextField = "Title";
                this.Combo.DataValueField = "Id";
                this.Combo.DataSource = libs;
                this.Combo.DataBind();
            */
 
            LibrariesManager man = new LibrariesManager();
            this.Combo.DataSource = man.GetAlbums();
            this.Combo.DataTextField = "Title";
            this.Combo.DataValueField = "Id";
            this.Combo.DataBind();
        
 
        protected override string LayoutTemplateName
        
            get
            
                return "ITOne.Sitefinity.Controls.Rotator.Designers.Resources.RotatorDesigner.ascx";
            
        
 
        protected override Type ResourcesAssemblyInfo
        
            get
            
                return this.GetType();
            
        
        /*
        public override IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences()
        
            var res = new List<ScriptReference>(base.GetScriptReferences());
            var assemblyName = this.GetType().Assembly.GetName().ToString();
            res.Add(new ScriptReference("ITOne.Sitefinity.Controls.Rotator.Designers.Resources.RotatorDesigner.js", assemblyName));
            return res.ToArray();
        */
    



If I uncomment the block above, it works fine, otherwise it doesn't. Since the designer is javascript based I guess javascript file with proper namespace is mandatory?

Thanks,
Robert

Posted by Community Admin on 01-Nov-2010 00:00

Hi Robert,

The control designer of the control cannot work properly as we have already discussed this in this post.

Best wishes,
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

This thread is closed