WebEditor/Control Designer in User Control

Posted by Community Admin on 04-Aug-2018 09:57

WebEditor/Control Designer in User Control

All Replies

Posted by Community Admin on 09-Jan-2012 00:00

In the good old 3.x days, we could create a public property in a user control, and then use a build in WebEditor to select a page from the site (or an image from a library, etc).

[Browsable(true), 
    Category("Event Settings"), 
    DisplayName("Thankyou Page"), 
    Description("Sets the page where a user will be taken on successful completion.")]
[WebEditor("Telerik.Cms.Web.UI.CmsUrlWebEditor, Telerik.Cms")]
public string TargetUrl
    get return targetUrl;
    set targetUrl = value;


It doesn't get much easier than that.  Now, it seems, I have to write a bunch of code to do this same simple thing for a user control.  Isn't there a simple way to attach an image selector, or page selector to a public property in a user control?  If not, why do I have to write the code for a control designer that's already used in other places in Sitefinity?  It seems like I should be able to decorate my property appropriately, and use one of the built-in control designers.  I've looked all though the documentation, but can't find anything...or am I missing something simple?

Note: This is a simple user control and a codebehind with a public property; it's not a content view or rotator or anything like that.

Regards,
Mike Sharp

Posted by Community Admin on 09-Jan-2012 00:00

Hi,

Please take a look at this forum post where you will find a sample.Here is a related useful blog post.

Kind regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested 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 09-Jan-2012 00:00

this is good write up but look at the amount of code that needs to be written now. What used to take 10 seconds will now take an hour if you are lucky. A big ommision in v4 IMHO.

Posted by Community Admin on 10-Jan-2012 00:00

Hello,

If you are not considering that designers have completely different way for loading and they are all AJAX based, you are partially right.

  • If you are using a custom designer with  WebEditor this would take the same time as the new implementation.
  • In the past you were not able to use client components and use objects sent from the server to the client, so you cannot perform such binding. 
  • Designers in 4.x uses standard ASP.NET methods that you will need in each other ASP.NET application to do the same thing.


Greetings,
Ivan Dimitrov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested 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 15-May-2012 00:00

My apologies in advance for the tone of this post, but I'm quite frustrated here.  Why is this so hard?  Selecting Sitefinity content in a user control widget seems like a fundamental use case.  I know it's possible; Sitefinity has lots of places where, for example, images are selected. 

The forum post sample in your reply is incredibly long and tortuous, with 24 separate entries!  I have no clue as to which reply in that post is the one you're referring to as a sample.  As an example of how to do this, it frankly sucks.  All you have to do is read the last two entries...both people are left confused, wondering if anyone had gotten it to work.

The VAST majority of the time, I don't need a fancy designer, just a simple way to select Sitefinity content, and persist it to the appropriate public property of the control.  It seems crazy to write all this code each time.  

Why can't I simply specify an OOTB image selector for the property in my control, the way I did in 3.7? If you're going to force me to write a custom designer for every control where I want to select some bit of Sitefinity content, you should at least have a simple example of how this is accomplished, that isn't buried in a megapost.  If the problem can't be answered without 24 entries in the thread, then the solution is too complex.

I've read through tons of posts, each of which seem to have a slightly (or significantly) different way of doing the same thing.  Sometimes they're about Field controls, and in the tons of questions that inevitably follow, there are a few vague references to doing it in a control designer.  But no practical example.  There's almost no consistent naming conventions, either.  No example of best practice (do you really expect me to write a separate custom designer for each of my user controls?)

I've got a ticket open where I've gotten several different suggestions on how to do this simple thing, none of which appear to have any bearing on the simple problem I'm trying to solve: How do I pick Sitefinity content in a custom widget that I've created.  The latest suggestion included a sample that was supposed to show how to use the MediaContentSelectorView, but I'll be damned if I can find anything that looks like a MediaContentSelectorView in the example that was attached.   This has been going on for weeks.  If it's too hard for your support engineers to explain, how can you expect us to do it?

Come on guys, you used to have a CMS that was designed to be easy for developers to customize.  None of the sites I've built over the past 4 years are candidates for migration, because it's just too damn painful.  Some of those sites were built in less than 20 hours of development, because I've been able to get a lot of code re-use. 

So here's my question for the last time.

I have a simple toolbox user control (widget) with a single public property, called ImageId.  It's not a field control for an existing content type, so don't point me to posts that talk about that.  All I want to do is pick an image from Sitefinity using the nice designer I see used everywhere else, and persist the selected ImageId to my widget.  If this is so easy, how about a real example?  I'll supply the widget:

The LayoutTemplate:

<%@ Control Language="C#" %> 
<asp:Image ID="TheImage" runat="server" />

The control class:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Sitefinity.Web.UI;
using Telerik.Sitefinity.Web.UI.ControlDesign;
using Telerik.Sitefinity.Modules.Pages.Web.UI;
using Telerik.Sitefinity.Modules.Libraries.Images;
using Telerik.Sitefinity;
  
namespace SitefinityWebApp.UserControls.Heros.SubHero
    public class ImageSelector : SimpleView
    
        protected Image TheImage
        
            get return Container.GetControl<Image>("TheImage", true);
        
  
        protected override void InitializeControls(GenericContainer container)
        
            if (Guid.Empty != ImageId)
            
                Telerik.Sitefinity.Libraries.Model.Image image = App.WorkWith().Image(ImageId).Get();
                TheImage.ImageUrl = image.MediaUrl;
            
            else
            
                TheImage.ImageUrl = ResolveUrl("~/Sitefinity/WebsiteTemplates/MySite/App_Themes/Default16/Images/Default_Sub_Hero.png");
            
        
  
        protected override string LayoutTemplateName
        
            get return "SitefinityWebApp.UserControls.Heros.SubHero.Resources.Templates.ImageSelector.ascx";
        
  
        private Guid _imageId;
        public Guid ImageId
        
            get return this._imageId;
            set this._imageId = value;
        
    

Ok, so how do I create the control designer for this?  Assume I'm the dumbest ASP.NET developer on the planet.  Don't make me use reflector or browse your assemblies to try to figure out whether I need using Telerik.Sitefinity.Modules.Libraries.Web.UI.Designers or using Telerik.Sitefinity.Web.UI.ControlDesign.  If I need a "using" statement, tell me about it.  Use a realistic naming convention for the files, and show me best practice for how I put this in my project, with a folder structure that's not stupid.   If possible, show me this example in a way that can facilitate it's re-use. 

If you can do that, I promise I'll stop bugging you. :)

Posted by Community Admin on 15-May-2012 00:00

Designers are obviously an asp.net concept, and were (of course) available to be implemented in V3 Sitefinity, but personally, I avoided them like the plague, because V3 web-editors were a 'good enough' solution for my needs, and just so much easier to whip up a control with.

However, with V4/5 Sitefinity, Telerik effectively tossed everyone in the deep end, and required that devs learn to create designers if they wanted anything more than the most simple of controls.

The learning curve is pretty steep, but once I got over that initial hump (and wrote my own base classes I could re-use) it now doesn't seem so bad. Still not as easy as the 'good old days' but not that bad, and I can certainly make more usable controls than before.

Josh Morales's blog post does a good job of explaining how to select Sitefinity content from a designer.
http://www.sitefinity.com/blogs/joshmorales/posts/11-10-05/selecting_sitefinity_4_content_inside_widget_designers.aspx

However, the one that gave me the biggest uh-huh! moment, was Gabe Sumner's "widget designers for dummies" (which is me) video - which I then adapted for my custom control application.

http://www.sitefinity.com/blogs/gabesumner/posts/11-08-29/ldquo_hello_world_rdquo_guide_to_custom_sitefinity_widgets_amp_controldesigners.aspx

This thread is closed