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

Forums / General Discussions / comment use text box instead of radeditor

comment use text box instead of radeditor

2 posts, 1 answered
  1. vinamra
    vinamra avatar
    45 posts
    Registered:
    23 Oct 2012
    09 Jun 2010
    Link to this post
    hi


    in blog comments i want to use plane textbox instead of rad editor

    i used textbox and named it as commentTxt but i know commenting system take radeditor's content property

    so how to do it.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Jun 2010
    Link to this post
    Hello vinamra,

    Here is what you have to do.

    1. Download Sitefinity's external templates and map - ListPageDetail.ascx template to BlogPosts control. The external templates can be downloaded through your account - Downloads section. Here is a post that explains how to map the template to BlogPosts control Working with presentation modes.

    2. Once you have the template modify it as shown below

    <%@ Control Language="C#" %>
    <%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection" TagPrefix="sfWeb" %>
    <%@ Register Assembly="Telerik.Blogs" Namespace="Telerik.Blogs.WebControls" TagPrefix="sfWeb" %>
      
    <%@ Register Assembly="App_Code" Namespace="Telerik.Samples" TagPrefix="fix" %>
      
      
    <telerik:CssFileLink ID="CssFileLink1" EmbeddedFileName="Telerik.Blogs.Resources.ControlTemplates.Frontend.blogsCommonLayout.css" FileName="" Media="screen" runat="server" />
    <telerik:JsFileLink id="jsLink" runat="server" ScriptType="jQuery" />
      
    <div runat="server" id="modeHidden">
    <asp:PlaceHolder ID="trackbackScript" runat="server">
      
    </asp:PlaceHolder>
      
    <div class="sf_singlePost">
        <p class="sf_back">
           <asp:HyperLink ID="backToList1" Text="<%$Resources:GoBack %>" runat="server"></asp:HyperLink>
        </p>
        <h1 class="sf_postTitle">
            <asp:Literal ID="Title" runat="server"></asp:Literal>
        </h1>
       <p class="sf_postAuthor">
            <asp:HyperLink ID="postedBy" runat="server">
                <asp:Literal ID="Author" runat="server"></asp:Literal>
            </asp:HyperLink>
        </p>
        <p class="sf_postDate">
            <asp:Literal ID="Publication_Date" runat="server" Text="{0}" />
        </p>
        <asp:Panel ID="pnlContent" runat="server" CssClass="sf_postContent">
            <asp:Literal ID="content" runat="server"></asp:Literal>
        </asp:Panel>
         <p class="sf_postCategory">
            <asp:HyperLink ID="Category" runat="server" />
         </p>
         <p class="sf_postTags">
            <asp:Repeater ID="Tags" runat="server">
                <ItemTemplate>
                    <asp:HyperLink ID="tagLink" runat="server" />
                </ItemTemplate>
            </asp:Repeater>
        </p>
        <p class="sf_postBookmark">
          <asp:Repeater ID="Bookmarks" runat="server">
              <ItemTemplate>
                    <asp:HyperLink ID="BookmarkLink" runat="server">
                        <asp:Image ID="BookmarkImage" runat="server" />
                    </asp:HyperLink>
              </ItemTemplate
          </asp:Repeater
        </p>
    </div>
      
    <div class="sf_postComments" runat="server" id="postCommentsPlh">
        <fix:BlogCommentsListCustom ID="commentsList" runat="server" CssClass="sf_commentsList" ValidationGroup="commentInfo">
                <LayoutTemplate>
            <asp:Repeater ID="commentsRepeater" runat="Server">
        <HeaderTemplate>
            <asp:PlaceHolder runat="server" ID="headerHolder">
                <h2 class="sf_comments">
                    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Comments %>" />
                     <asp:Literal ID="commentsCount" runat="server"></asp:Literal>
                </h2>
            </asp:PlaceHolder>
            <ul class="sf_commentListing">
        </HeaderTemplate>
        <ItemTemplate>
            <!-- comment goes here -->
            <sfWeb:CommentItem Id="anonCommentContainer" runat="server" CssClass="sf_anonymousComment" >
              
             <Template>
               <p class="sf_commentAuthor">
                    <strong>
                        <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink>
                        <asp:Literal runat="Server" ID="authorName"  Visible="false"></asp:Literal>
                    </strong>
                    <%--<abbr class="sf_commentDate" id="commentDate" runat="server" > </abbr>--%>
                    <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="" />
                </p>
                <asp:Label ID="text" runat="server"></asp:Label>
            </Template>
             
            </sfWeb:CommentItem>
             
            <sfWeb:CommentItem Id="authorCommentContainer" runat="server"  CssClass="sf_authorComment">
             <Template>
                 <p class="sf_commentAuthor">
                    <strong>
                        <asp:HyperLink ID="webSiteLink" runat="server" Visible="false" rel="nofollow"></asp:HyperLink>
                        <asp:Literal runat="Server" ID="authorName"  Visible="false" ></asp:Literal>
                    </strong>
                    <%--<abbr class="sf_commentDate" id="commentDate" runat="server"> </abbr>--%>
                    <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="" />
                </p>
                <asp:Label ID="text" runat="server"></asp:Label>
             </Template>
              
           </sfWeb:CommentItem>
              
        </ItemTemplate>
        <FooterTemplate>
            </ul>
        </FooterTemplate>
    </asp:Repeater>
    <asp:PlaceHolder ID="moderationHolder" runat="server" Visible="false">
        <p class="sf_commentMessage">
            <asp:Literal ID="Literal2" runat="server" Text="<%$Resources:CommentMessageModeration %>"></asp:Literal>
        </p>
    </asp:PlaceHolder>
      
        <fieldset class="sf_postNewComment">
            <legend>Post a comment!</legend>
            <ol>
                <li>
                    <asp:Label ID="Label2" runat="Server" Text="<%$Resources:Name %>" AssociatedControlID="authorTxt"></asp:Label>
                    <asp:TextBox ID="authorTxt" runat="server" size="30"></asp:TextBox>
                    <asp:RequiredFieldValidator runat="server" ID="authorVal" ControlToValidate="authorTxt"
                            ErrorMessage="<%$Resources:NameEmpty %>" Display="dynamic"
                            CssClass="sf_commentsValidator"></asp:RequiredFieldValidator>
      
                </li>
                <li>
                    <asp:Label ID="Label3" runat="Server" Text="<%$Resources:Email %>" AssociatedControlID="emailTxt"></asp:Label>
                    <asp:TextBox ID="emailTxt" runat="server" size="30"></asp:TextBox>
                    <asp:RegularExpressionValidator runat="server" ID="emailVal" ControlToValidate="emailTxt"
                            ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="<%$Resources:InvalidEmail %>"
                            Display="dynamic" CssClass="sf_commentsValidator"></asp:RegularExpressionValidator>
                </li>
                <li>
                    <asp:Label ID="Label4" runat="Server" Text="<%$Resources:WebSite %>" AssociatedControlID="webSiteTxt"></asp:Label>
                    <asp:TextBox ID="webSiteTxt" runat="server" size="30"></asp:TextBox>
                </li>
                <li class="texarea-wrapper">
                    <asp:Label ID="Label1" visible="false" runat="Server" Text="<%$Resources:Comment %>" AssociatedControlID="textboxContentTxt"></asp:Label>
                    <div>
                        <a visible="false" href="#" class="formattingOptionsToggleBtn" onclick='if($(this).parent().hasClass("formattingOptions")){$(this).parent().removeClass("formattingOptions");$(this).text("Formatting options");}else{$(this).parent().addClass("formattingOptions");$(this).text("Hide formatting options"); } return false;'></a>
                    
                  <asp:TextBox runat="server"  TextMode="MultiLine"  Rows="10" ID="textboxContentTxt" ></asp:TextBox>
                    
                    
                    </div
                     <asp:RequiredFieldValidator runat="server" ID="contentVal"
                            ControlToValidate="textboxContentTxt"
                            ErrorMessage="<%$Resources:CommentEmpty %>"
                            Display="dynamic"
                            ValidationGroup="commentInfo"
                            CssClass="sf_commentsValidator">
                            <strong>Message text is required</strong>
                     </asp:RequiredFieldValidator>                                                                                                                   
                </li>          
                <li>
                  
                </li>
            </ol>
        </fieldset>
      
            </LayoutTemplate>
        </fix:BlogCommentsListCustom>
    </div>
      
    </div>

    3. Create the custom class shown below in App_Code folder or  compile it. In the class below RadEditor control is set as not required control and it is not used anywhere. Instead of the RadEditor I use TextBox control.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Blogs.WebControls;
    using Telerik.Web.UI;
    using System.Web.UI;
    using Telerik.Cms.Engine.SpamProtector;
    using Telerik.Cms.Engine;
    using System.Web.UI.WebControls;
    using Telerik.Security;
    using System.Collections;
    using Telerik.Framework.Web;
    using Telerik.Cms.Engine.WebControls;
      
    /// <summary>
    /// Summary description for BlogCommentsListCustom
    /// </summary>
    ///
      
    namespace Telerik.Samples
    {
        public class BlogCommentsListCustom : BlogCommentsList
        {
            public BlogCommentsListCustom()
            {
      
            }
            /// <summary>
            /// sets the path to the template that the control will use
            /// </summary>
            public override string LayoutTemplatePath
            {
                get
                {
                    return "~/Sitefinity/ControlTemplates/Blogs/CommentsList.ascx";
                }
      
            }
      
            /// <summary>
            /// here the base logic goes
            /// </summary>
            /// <param name="controlContainer"></param>
            protected override void InitializeControls(Control controlContainer)
            {
                //base.InitializeControls(controlContainer);
                if (this.Page == null)
                {
                    Control radEditor = this.Container.GetControl<RadEditor>(TraverseMethod.BreadthFirst);
                    radEditor.Visible = false;
                }
      
                this.dataSource = this.Manager.GetComments(this.ParentID, true, this.SortBy);
                this.Content = this.Manager.GetContent(this.ParentID);
      
                if (this.dataSource.Count > 0 && this.Visible)
                {
                    this.CommentsRepeater.DataSource = this.dataSource;
                    this.CommentsRepeater.ItemDataBound += this.CommentsRepeater_ItemDataBound;
                    this.CommentsRepeater.Visible = true;
                    this.CommentsRepeater.DataBind();
                }
                else
                    this.CommentsRepeater.Visible = false;
      
                this.SubmitButton.Command += this.SubmitButton_Command;
      
                if (this.Page != null)
                    this.Page.MaintainScrollPositionOnPostBack = true;
      
                string valGroup = string.IsNullOrEmpty(ValidationGroup) ? "commentInfo" : ValidationGroup;
                if (this.ContentVal != null)
                    this.ContentVal.ValidationGroup = valGroup;
                this.AuthorVal.ValidationGroup = valGroup;
                if (this.EmailVal != null)
                    this.EmailVal.ValidationGroup = valGroup;
                this.SubmitButton.ValidationGroup = valGroup;
                if (this.SpamProtector != null)
                {
                  // spam protector is disabled
                }
            }
      
            /// <summary>
            /// this triggers when we click on the submit button
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void SubmitButton_Command(object sender, CommandEventArgs e)
            {
                string webSite = string.Empty;
                if (Page.IsValid && this.ParentID != Guid.Empty)
                {
                    if (this.WebSiteText.Text.StartsWith("http://") || this.WebSiteText.Text.StartsWith("https://"))
                        webSite = this.WebSiteText.Text;
                    else if (!String.IsNullOrEmpty(this.WebSiteText.Text))
                        webSite = "http://" + this.WebSiteText.Text;
      
                    using (Protector spam = new Protector())
                    {
                        IComment comment = this.Manager.CreateComment(this.Content);
      
                        comment.Text = this.TextBoxCommentText.Text;
                        comment.Author = this.AuthorText.Text;
                        comment.Email = this.EmailText.Text;
      
                        comment.WebSite = webSite;
      
                        comment.Visible = (!this.Moderation) &&
                                          (!spam.IsSpamContent(webSite, this.AuthorText.Text,
                                                               this.TextBoxCommentText.Text));
                        comment.IpAddress = this.Page.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                        if (String.IsNullOrEmpty(comment.IpAddress))
                            comment.IpAddress = this.Page.Request.ServerVariables["REMOTE_ADDR"];
                        comment.Owner = SecurityManager.GetCurrentUserName();
      
                        this.Manager.SaveComment(comment);
      
                        if (this.Moderation)
                            this.ModerationHolder.Visible = true;
                        else
                        {
                            this.Manager.MarkCommentAsRead(comment, String.Empty);
                            this.ChildControlsCreated = false;
                        }
                    }
      
                    CleanUpCommentForm();
                }
            }
      
      
            /// <summary>
            /// binding the repeater of comments
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            protected void CommentsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
            {
                Control ctrl;
                if (e.Item.ItemType == ListItemType.Header)
                {
                    ctrl = e.Item.FindControl("headerHolder");
                    this.CheckControl(ctrl, typeof(PlaceHolder), "headerHolder");
      
                    if (this.dataSource.Count == 0)
                        ctrl.Visible = false;
      
                    ctrl = e.Item.FindControl("commentsCount");
                    this.CheckControl(ctrl, typeof(ITextControl), "commentsCount");
      
                    ITextControl headerTxt = ctrl as ITextControl;
                    if (headerTxt != null) headerTxt.Text = this.dataSource.Count.ToString();
                }
                else if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    IComment comment = (IComment)this.dataSource[e.Item.ItemIndex];
      
                    #region Comment Item
      
                    CommentItem anonCommentItem = (CommentItem)e.Item.FindControl("anonCommentContainer");
                    CommentItem authorCommentItem = (CommentItem)e.Item.FindControl("authorCommentContainer");
      
                    CommentItem commentItem = null;
      
                    if (IsAuthorComment(comment))
                    {
                        if (authorCommentItem != null)
                        {
                            commentItem = authorCommentItem;
      
                            if (anonCommentItem != null)
                                anonCommentItem.Visible = false;
                        }
                    }
                    else
                    {
                        if (anonCommentItem != null)
                        {
                            commentItem = anonCommentItem;
      
                            if (authorCommentItem != null)
                                authorCommentItem.Visible = false;
                        }
                    }
      
                    if (commentItem != null)
                        commentItem.LoadTab(comment);
      
                    #endregion
                }
            }
      
            /// <summary>
            /// helper method that cleans the form fields
            /// </summary>
            private void CleanUpCommentForm()
            {
                this.TextBoxCommentText.Text = String.Empty;
                this.AuthorText.Text = String.Empty;
                this.EmailText.Text = String.Empty;
                this.WebSiteText.Text = String.Empty;
            }
      
            /// <summary>
            /// helper method that checks for requered controls
            /// </summary>
            /// <param name="ctrl"></param>
            /// <param name="ctrlType"></param>
            /// <param name="id"></param>
            private void CheckControl(Control ctrl, Type ctrlType, string id)
            {
                if (ctrl == null || !ctrlType.IsAssignableFrom(ctrl.GetType()))
                    throw new HttpException(String.Format("RequiredControlNotFound"
                    , this.GetType().FullName, ctrlType.FullName, id));
            }
      
            /// <summary>
            /// control reference to the RadEditor contoro - make it not required and remove it from the template
            /// </summary>
            protected override RadEditor CommentText
            {
                get { return base.Container.GetControl<RadEditor>("commentTxt", false); }
            }
      
            /// <summary>
            /// add control reference to TextBox control that is declared into template
            /// </summary>
            protected virtual IEditableTextControl TextBoxCommentText
            {
                get { return base.Container.GetControl<IEditableTextControl>("textboxContentTxt", true); }
            }
      
            private IList dataSource;
        }
    }


    Sincerely yours,
    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.
    Answered
2 posts, 1 answered