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

Forums / Developing with Sitefinity / Replace RadEditor with ASP TextBox

Replace RadEditor with ASP TextBox

9 posts, 0 answered
  1. Joel
    Joel avatar
    10 posts
    Registered:
    04 Oct 2008
    09 Mar 2009
    Link to this post
    Looking for a quick way to replace the RadEditor on the blog commenting single item display page with an ASP.Net simple TextBox. I've been developing modules for some time and in doing so I feel like I am going to hit a wall here, or just lack the knowledge on making the modification necessary to your own modules to do this. I hoped the module template was using an ITextControl interface and I could just swap out the RadEditor with a TextBox with the same ID, but it's a no go. Any  help? Thanks in advance for what I am sure will be a simple solution.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Mar 2009
    Link to this post
    Hello Joel,

    If you are using version 3.6 you can replace the RadEditor control in the template. For versions prior 3.6 there is no way to do it - you need to create your own module with this implementation. However, under 3.6 you need to map a template which you want to modify, then comment the RadEditor control and add your TextBox control. Note that you TextBox control should have the same ID as the RadEditor.

    Exmaple:
     <asp:TextBox ID="Editor" runat="server"></asp:TextBox> 

    Under 3.6 you can also override the existing RadEditor control

    Example (here we are overriding RadEditro in NewsItemEdit template) :

    public class ReplaceEditor : NewsItemEdit 
        protected override System.Web.UI.IEditableTextControl Editor 
        { 
            get 
            { 
                return base.Editor; 
            } 
        } 

    I hope this helps.

    Sincerely yours,
    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.
  3. Joel
    Joel avatar
    10 posts
    Registered:
    04 Oct 2008
    09 Mar 2009
    Link to this post
    Ivan,

    I apologize, perhaps you can explain further. I do not understand the need to override if the original class did not use specific class types instead of using generic type interfaces. I replaced the RadEditor with an ASP TextBox again, what I didn't mention in my previous post is I am using 3.6 currently, but I did not get an error when the page rendered, only when posting back:

    A required control was not found in the template for "". The control must be assignable form type "Telerik.Web.UI.RadEditor" and must have ID "commentTxt".

    Here is my new template code for the commentTxt field:

    <asp:TextBox ID="commentTxt" runat="server"></asp:TextBox>

    It appears to me that the RadEditor is specifically being expected here, the error does not say anything about the object not being compliant with an interface description.

    Thanks in advance for your thoughts.

    Joel
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Mar 2009
    Link to this post
    Hi Joel,

    I was thinking about different RadEditor instance that is for insert and edit items. As I see you are asking for one of the editors that is used to manage comments, which makes the things completely different - for this templates the RadEditor is required

       protected virtual RadEditor CommentText 
            { 
                get { return base.Container.GetControl<RadEditor>("commentTxt"true); } 
            } 

    Fortunately I spent some time and wrote a solution for you. It is prepared for blogs, but you could get the logic and modify the code I am sending you for every module. First you need to crate a new class in App_Code. In this class you should inherit from the base view CommnetsEdit- View for editing comments. Then create a new property for your textbox and set the RadEditor control as not required. The following methods should be overriden as well : InitializeControls, CommentsButtons_Command

    using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Web; 
    using System.Web.UI; 
    using Telerik.Cms.Engine.WebControls.Admin; 
    using Telerik.Web.UI; 
    using Telerik.Cms.Engine; 
    using Telerik.Security.Permissions; 
    using System.Web.UI.WebControls; 
    using Telerik.Blogs.WebControls.Admin; 
     
    /// <summary> 
    /// Summary description for MyCommentsEdit 
    /// </summary> 
    public class MyCommentsEdit : Telerik.Cms.Engine.WebControls.Admin.CommentsEdit<BlogCommentsView> 
        #region Properties 
     
        public override System.Type AssemblyInfo 
        { 
            get 
            { 
                return typeof(GenericControlPanel); 
            } 
            set 
            { 
                base.AssemblyInfo = value; 
            } 
        } 
     
        public override Type LocalizationAssemblyInfo 
        { 
            get 
            { 
                return typeof(GenericControlPanel); 
            } 
            set 
            { 
                base.LocalizationAssemblyInfo = value; 
            } 
        } 
     
        protected override Telerik.Web.UI.RadEditor CommentText 
        { 
            get 
            { 
                return base.Container.GetControl<RadEditor>("commentText"false); 
            } 
        } 
     
        // ID of TextBox is "CustomBox"; 
        protected virtual IEditableTextControl CustomTextBox 
        { 
            get { return base.Container.GetControl<IEditableTextControl>("CustomBox"true); } 
        } 
        #endregion 
     
     
        protected override void InitializeControls(Control viewContainer) 
        { 
                IComment comment = null
                Guid commentId = Guid.Empty; 
                if (this.Page.Request.QueryString[this.ParameterKey] != null
                { 
                    commentId = new Guid(this.Page.Request.QueryString[this.ParameterKey]); 
                    comment = this.Host.Manager.GetComment(commentId); 
                } 
     
                this.BackButton.NavigateUrl = this.GetCancelCommand(); 
                this.CancelBtn.NavigateUrl = this.GetCancelCommand(); 
     
                this.SaveBtn.CommandName = "Save"
                this.SaveBtn.CommandArgument = commentId.ToString(); 
                this.SaveBtn.Command += this.CommentsButtons_Command; 
     
                if (comment != null
                { 
                    if (comment.Parent != null
                    { 
                        this.ParentLink.NavigateUrl = this.GetParentItemCommand(comment.Parent.ID.ToString()); 
                        this.ParentLink.Text = (string)comment.Parent.GetMetaData(this.Host.Manager.Provider.DefaultMetaField); 
                    } 
                    else 
                        this.ParentLink.Visible = false
     
                    this.CustomTextBox.Text = comment.Text; 
                    this.AuthorText.Text = comment.Author; 
                    this.EmailText.Text = comment.Email; 
                    this.WebSiteText.Text = comment.WebSite; 
                    this.CommentVisibility.SelectedValue = comment.Visible ? "Visible" : "Hidden"
                } 
        } 
     
        private void CommentsButtons_Command(object sender, CommandEventArgs e) 
        { 
            Guid commentId = new Guid(e.CommandArgument.ToString()); 
            IComment comment = this.Host.Manager.GetComment(commentId); 
            switch (e.CommandName) 
            { 
                case "Cancel"
                    break
                case "Save"
                    this.Host.Manager.GetPermission(CrudRights.Modify).Demand(); 
                    if (comment != null
                    { 
                        comment.Text = this.CustomTextBox.Text; 
                        comment.Author = this.AuthorText.Text; 
                        comment.Email = this.EmailText.Text; 
     
                        if (this.WebSiteText.Text.StartsWith("http://")) 
                            comment.WebSite = this.WebSiteText.Text; 
                        else if (!String.IsNullOrEmpty(this.WebSiteText.Text)) 
                            comment.WebSite = "http://" + this.WebSiteText.Text; 
     
                        comment.Visible = this.CommentVisibility.SelectedValue == "Visible" ? true : false
                    } 
                    this.Host.Manager.SaveComment(comment); 
                    this.RedirectOnSave(string.Empty); 
                    break
                case "ShowParent"
                    break
                case "ShowComments"
                    break
     
            } 
        } 
     


    Then you need to change the tamlate and replace all controls that use the old ID of the RadEditor - there are some literal controls and validators.

    <asp:Label ID="Label1" runat="Server" Text="<%$Resources:Comment %>" AssociatedControlID="CustomBox"></asp:Label> 
                       
                      <asp:TextBox ID="CustomBox" runat="server" TextMode="MultiLine" Rows="7"></asp:TextBox> 
                 <%--   <telerik:RadEditor  
                            runat="server"  
                            ID="commentTxt" 
                            ToolsFile="~/Sitefinity/ControlTemplates/Blogs/ToolsFile.xml" 
                            EnableEmbeddedSkins="True"  
                            Skin="WebBlue"  
                            EditModes="Design,Html">                 
                        <CssFiles> 
                            <telerik:EditorCssFile Value="~/Sitefinity/ControlTemplates/Blogs/EditorCssFile.css" /> 
                        </CssFiles> 
                     </telerik:RadEditor>  --%>  
                     <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"  
                            ControlToValidate="CustomBox" 
                            ErrorMessage="<%$Resources:CommentEmpty %>"  
                            Display="dynamic"  
                            ValidationGroup="commentInfo" 
                            CssClass="sf_commentsValidator"
                            <strong>Message text is required</strong> 
                     </asp:RequiredFieldValidator>     


     Finally you should map your template and replace the view with the custom one.

    <viewSettings hostType="Telerik.Blogs.WebControls.Admin.BlogCommentsView, Telerik.Blogs"
          <views> 
            <remove name="BlogCommentsEditView"></remove> 
            <add name="BlogCommentsEditView" viewType="MyCommentsEdit, App_Code"></add> 
          </views> 
        </viewSettings> 
        <viewSettings hostType="MyCommentsEdit, App_Code" layoutTemplatePath="~/Sitefinity/Admin/Externel/Blogs/CommentsEdit.ascx"
        </viewSettings> 

    I hope this helps.


    Best wishes,
    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. Joel
    Joel avatar
    10 posts
    Registered:
    04 Oct 2008
    10 Mar 2009
    Link to this post
    Ivan,

    You are amazing. I have not tested this code, but I will and report back. This sample is huge for me as it gives me insight into other methods of working in similar situations.

    Here is my plan moving forward:

    1. Post on the Sitefinity forums about how amazing Ivan is (complete)
    2. Test Ivan's code
    3. Report back to Ivan on success or failure of code
    4. Blog about Ivan's amazing skills and Sitefinity's great support

    I have never seen developers provide sample code like you guys at Sitefinity have for people with questions. This will definitely make a huge difference in the success of your product.
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 Mar 2009
    Link to this post
    Hello Joel,

    Let me know if you get stuck and need further assistance. Our team will be pleased to help you.

    Greetings,
    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.
  7. Joel
    Joel avatar
    10 posts
    Registered:
    04 Oct 2008
    13 Mar 2009
    Link to this post
    Ivan,

    I believe you got me on the right track, but I've hit a wall, I wanted to use your sample to move forward on my own (it was not exactly what I wanted to do, but I feel like I've hit another roadblock). Before I get into it, I was using .Net Reflector against your base code to determine how to build my inherited classes (is that appropriate)? I may simply end up using the RadEditor in the end, but I would still like to understand exactly how I need to do this.

    The control I am using is this:

    Sitefinity\ControlTemplates\Blogs\ContentViewSingleItem.ascx

    I wanted to modify this control to no longer us the RadEditor, but an ASP.Net TextBox control.

    I noticed it is using an instance of BlogCommentsList within the template. This lead me to look further into both Telerik.Blogs.WebControls.BlogPosts and Telerik.Blogs.WebControls.BlogCommentsList classes. I believe I need to created a modified version of this Telerik.Blogs.WebControls.BlogCommentsList class (unless I am not understanding). The problem is, I do not know what <views> to remove/add to the controls.config (are they defined somewhere?). It seems like the new flow control you have set up in 3.6 is very flexible, but I need to know what to modify the flow to utilize my own classes to do this I think.

    In your sample controls.config file, It  provides all template information, but I need to know details for the individual views themselves (which define the flow of the viewsettings node). Does a master list exist somewhere? Or is there an easy way for me to look at any module and figure out what views I need to remove/add to utilize my own custom code?

    I would also like to recommend Sitefinity utilize Interfaces everywhere possible in the future to avoid issues like this. I may end up not using the RadEditor, but i would really like to have options other than to go through the steps I am to make such a simple change to a template.

    I am thinking I need to add a custom class to the App_Code folder that inherits Telerik.Blogs.WebControls.BlogCommentsList and modify the following code in the controls.config (as well as make custom changes to the templates):

        <viewSettings hostType="Telerik.Blogs.WebControls.BlogPosts">
          <additionalTemplates>
            <!--Provides user interface for displaying a list of posts in the BlogPosts control in the blogs module.-->
            <add key="ItemListTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Blogs/ContentViewItemList.ascx" />
            <!--Provides user interface for displaying a single post in the BlogPosts control in the blogs module.-->
            <add key="SingleItemTemplatePath" layoutTemplatePath="~/Sitefinity/ControlTemplates/Blogs/ContentViewSingleItem.ascx" />
          </additionalTemplates>
        </viewSettings>

    Let me know if I am on the right track. Thank you very much for your reply.
  8. ColinBowern
    ColinBowern avatar
    20 posts
    Registered:
    12 Aug 2012
    18 Mar 2009
    Link to this post
    I am hitting the exact same wall.~26nbsp~3b The challenge is that the CommentText in the Telerik.Cms.Engine.WebControls.CommentsList class is a RadEditor~2c not an ITextControl.~3cbr /~3e ~3cbr /~3e How do we minimally override to make that change~3f~3cbr /~3e
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    19 Mar 2009
    Link to this post
    Hello,


    In your sample controls.config file, It  provides all template information, but I need to know details for the individual views themselves (which define the flow of the viewsettings node). Does a master list exist somewhere? Or is there an easy way for me to look at any module and figure out what views I need to remove/add to utilize my own custom code?

    Unfortunately we have not documented all views one by one. You can gather more information about the whole architecture from this post  Sitefinity 3.6 new backend architecture - Architectural overview . It will be difficult for you searching with reflector to find out the view, thus we shipped referenced files with all views. Generally, you should follow the architecture of the module examples - thus you will be able to use them in other projects with higher version and you will be sure that everything will work fine. The main idea of the views is that you create class and control template for each view. In the class you use WebSysTemplate to specify the path to control template for your view - you gets/sets the path to a custom layout template for your control.

    We have planned to integrate interfaced for template mapping and other features that we will release in Sitefinity 4.0, where we will change GC architecture as well.

    The problem with the radeditor is that it is a required control and this was the reason for creating  a custom view - where the control is not required. Generally, this way requires removing the child view and replacing it with the custom one. We are creating a new view , for instance  MyCommentsEdit  that ingherits Telerik.Cms.Engine.WebControls.Admin.CommentsEdit<BlogCommentsView>.

    Just to let you know you can find our temporarily TOC here

    Sincerely yours,
    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.
Register for webinar
9 posts, 0 answered