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

Forums / Suggestions / Need TextArea control on edit panel of a Usercontrol

Need TextArea control on edit panel of a Usercontrol

12 posts, 0 answered
  1. kranthi
    kranthi avatar
    4 posts
    Registered:
    19 Mar 2009
    09 Apr 2009
    Link to this post
    Hi all,

    I just started working with creating usercontrols in application which uses sitefinity. Everything went fine, I have created a user control in Visual Studio and added reference in web.config file, It has shown up in the Sitefinity UI while editing the application in Admin mode.

    I have defined to public properties in the usercontrol, when i drag the created usercontrol on to a ContentPlace holder and click Edit on UserControl, The Two Properties which i have created aer shown up as Textbox to enter string, as the return type of the properties are strings.

    At this point my probelm arises, On edit of UserControl i need to get TextArea(RadEditor control) for one of the properties, how to achive this.

    Thanks,
    Kranthi
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 Apr 2009
    Link to this post
    Hi kranthi,

    You need to create a custom WebEditor for this property and set the value ot the RadEditor's content area to your TextArea or another field you have.

    Here is a basic sample that demonstrates requires functionality.

    Here we are creating our custom WebEditor as a class in our App_Code folder.

    using Telerik.Web.UI; 
     
    /// <summary> 
    /// Summary description for MyWebEditor 
    /// </summary> 
    ///  
     
    namespace Telerik.Samples 
        public class MyWebEditor : Telerik.Cms.Web.UI.WebUITypeEditor<string
        { 
            public MyWebEditor() 
            { 
            } 
     
            protected override void CreateChildControls() 
            { 
                RadEditor editor = new RadEditor(); 
                editor.ID = "editor1"
                editor.Skin = "Vista"
                editor.Visible = true
                Controls.Add(editor); 
            } 
     
            public override string Value 
            { 
                get{return my_value;} 
                set{my_value = value;}    
            } 
            private string my_value; 
        } 

    Then, we use this WebEditor in our control property.

     #region properties 
        [Telerik.Cms.Web.UI.WebEditor("Telerik.Samples.MyWebEditor, App_Code")] 
        public string MyText 
        { 
            get {return mytext; } 
            set { this.mytext = value;} 
        } 
        #endregion 
        #region privateStrings 
     
        private string mytext; 
        #endregion 

    More information about custom WebEditors can be found at SitefinityWatch

    All the best,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer , the state of the art learning tool for Telerik products.
  3. kranthi
    kranthi avatar
    4 posts
    Registered:
    19 Mar 2009
    15 Apr 2009
    Link to this post
    Hi Ivan,
    I have tried creating MyWebEditor class in app_code and defined the publich property MyText in the UserControl.
    At this point i am getting the RadEditor in the edit mode of the property of usercontrol, but when i am clicking "I'm done" the value which i entered in the RadEditor is getting lost. and i am not getting any value in the textbox beside the MyText property in the edit mode of that usercontrol.

    I have tried setting the breakpoint at get{return my_value;}  in MyWebEditor. After clicking "I'm Done" button it is returning null value.

    Thanks,
    Kranthi
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Apr 2009
    Link to this post
    Hi kranthi,

    You should get the value from RadEditor content area and set it to the TextBox.

    All the best,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. kranthi
    kranthi avatar
    4 posts
    Registered:
    19 Mar 2009
    15 Apr 2009
    Link to this post
    Thanks a lot Ivan, that has worked :)
  6. Graeme
    Graeme avatar
    1 posts
    Registered:
    11 Mar 2009
    11 May 2009
    Link to this post

    I think the sample code that you've provided is a bit misleading?

    I got the same problem that the other guy had, which was that when I hit the 'I'm done' button it didn't retain the value from the custom editor popup window - instead of defining the RadEditor inside the CreateChildControls() method, I made it a member level variable - I then return editor.Content in the Value property.

    Is this the right approach?

    Thanks

  7. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    12 May 2009
    Link to this post
    Hello Graeme,

    Thanks for pointing this out. There is no difference in what you do; in the end the Valueproperty must return the value that will be set to the property to which the WebEditorAttribute is applied.

    You can achieve this with member variable and events, or directly exposing RadEditor.

    Greetings,
    Dido
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Adam
    Adam avatar
    33 posts
    Registered:
    23 Feb 2009
    10 Nov 2009
    Link to this post
    The webeditor attribute forces the textbox to display a "select" button next to it. Then when the user hits that button, they are taken to the dialog that displays that content within the desired control. However, this is not very intuitive for the average user. Why would  I hit select to add some basic content. Is there a way to display the radeditor in place of the textbox, or at the very least change the textbox to a label?
  9. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    10 Nov 2009
    Link to this post
    Hi Adam,

    The RadEditor approach is achievable. However for this you would have to develop custom control designers for setting some properties. Then you will be able to set a markup for those control designers and add a RadEditor to the control designer. More information on how to develop custom control designers can be found here:
    Mapping ContentViewDesigners and working with Presentation Modes
    Implementing Control Designers

    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.
  10. Mike
    Mike avatar
    7 posts
    Registered:
    13 Nov 2008
    15 Apr 2010
    Link to this post
    "You should get the value from RadEditor content area and set it to the TextBox."

    Could you please provide an example as to how this might work. I have the radeditor displaying on selecting the mytext field. From what I can see in the sitefinity API your code example shown here should work.
    Thanks.
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Apr 2010
    Link to this post
    Hi Mike,

    Blow is a sample code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Cms.Web.UI;
    using Telerik.Web.UI;
     
    /// <summary>
    /// Summary description for RadEditorSelector
    /// </summary>
    public class RadEditorSelector : WebUITypeEditor<String>
    {
        public RadEditorSelector()
        {
        }
     
        public override string Value
        {
            get
            {
               if(!String.IsNullOrEmpty(editor.Content.ToString()))
                return (string)editor.Content;
               return _value;
            }
            set
            {
                this._value = value;
            }
        }
     
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            ControlWithCustomDesigner c = new ControlWithCustomDesigner();
            editor = new RadEditor();
            editor.ToolsFile = "~/Sitefinity/Admin/ControlTemplates/EditorToolsFile.xml";
            Controls.Add(editor);
            string editorContent = this.editor.Content;
             
            if (String.IsNullOrEmpty(Value))
                this.Value = editor.Content.ToString();
                this.Value = c.RadEditiorDialogValue;
            editor.Content = this.Value;
        }
     
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
        }
     
        private RadEditor editor;
     
        private string _value;
     
    }


    Note that you should create a template for the custom WebEditor and make control reference to the RadEdtior control that has to be declared in the template.

    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.
  12. Mike
    Mike avatar
    7 posts
    Registered:
    13 Nov 2008
    19 Apr 2010
    Link to this post
    Thanks Ivan, that is now working for me. The only thing I needed to change from your sample was to remove references the 'ControlWithCustomDesigner' object as I had no need for using a custom template.
Register for webinar
12 posts, 0 answered