Add custom field in Blog comment post

Posted by Community Admin on 04-Aug-2018 10:53

Add custom field in Blog comment post

All Replies

Posted by Community Admin on 15-Jun-2011 00:00

I have 2 dropdown list which contains "ddlPractice" and "ddlService". I have added these dropdownlist in Blog comment post area on my custom blog details page
When post the comment I want to store these drop downlist value in database. how can i achieve this. Please give some xport advice.

Below is my Blog Details Template code

001.<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Custom_ContentViewSingleItem.ascx.cs"
002.    Inherits="Sitefinity_ControlTemplates_Blogs_Custom_ContentViewSingleItem" %>
003.<%@ Register Assembly="Telerik.Cms.Engine" Namespace="Telerik.Cms.Engine.WebControls"
004.    TagPrefix="sfWeb" %>
005.<%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Web.UI.SpamProtection"
006.    TagPrefix="sfWeb" %>
007.<%@ Register Assembly="Telerik.Cms.Web.UI" Namespace="Telerik.Cms.Web.UI" TagPrefix="sfWeb" %>
008.<%@ Register Assembly="Telerik.Blogs" Namespace="Telerik.Blogs.WebControls" TagPrefix="sfWeb" %>
009.<telerik:CssFileLink ID="CssFileLink1" EmbeddedFileName="Telerik.Blogs.Resources.ControlTemplates.Frontend.blogsCommonLayout.css"
010.    FileName="" Media="screen" runat="server" />
011.<telerik:JsFileLink ID="jsLink" runat="server" ScriptType="jQuery" />
012.  
013.<style type="text/css">
014.textarea width: 100%; height: 250px
015.</style>
016.  
017.  
018.  
019.<div class="wrap">
020.    <div id="section">
021.        <h1>
022.            <asp:HyperLink ID="fullContent1" runat="server">
023.                <asp:Literal ID="Title" runat="server"></asp:Literal>
024.            </asp:HyperLink>
025.        </h1>
026.        <div class="meta">
027.            <p>
028.                <asp:Literal ID="Literal2" runat="server" Text="By "></asp:Literal>
029.                <asp:HyperLink ID="postedBy" runat="server">
030.                    <asp:Literal ID="Author" runat="server"></asp:Literal>
031.                </asp:HyperLink>
032.                |
033.                <telerik:DateTimeLiteral runat="server" ID="Publication_Date" DateFormatString="MMM dd, yyyy">
034.                </telerik:DateTimeLiteral>
035.                <asp:HyperLink ID="Category" runat="server" />
036.            </p>
037.        </div>
038.        <div class="article">
039.            <p>
040.                <asp:Panel ID="pnlContent" runat="server" CssClass="article">
041.                    <asp:Literal ID="content" runat="server"></asp:Literal>
042.                </asp:Panel>
043.            </p>
044.            <p>
045.                <img src="img/img.gif"></p>
046.            <p>
047.                <strong>This is a paragraph header</strong><br>
048.                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce egestas sodales nibh.
049.                Integer lectus purus, blandit nec tincidunt ut, hendrerit vel ipsum. Suspendisse
050.                purus lectus, molestie viverra tristique sed, vulputate eget nunc. Morbi porta venenatis
051.                risus non faucibus. Quisque lacinia venenatis dolor, quis semper erat viverra nec.
052.                Cras ac felis eros, at elementum lectus. Proin non augue felis, quis luctus nunc.</p>
053.            <p>
054.                <strong>Ut aliquam scelerisque ipsum interdum dapibus</strong><br>
055.                Etiam ipsum orci, dictum eget gravida sit amet, tristique eget eros. Sed vitae est
056.                a est aliquam gravida quis vitae augue. Vestibulum non placerat lacus. Nam et eros
057.                quis tellus elementum gravida et aliquet risus. Ut non lorem auctor metus interdum
058.                molestie. Praesent non gravida metus. Pellentesque posuere lobortis justo ut tempor.
059.                Sed commodo tempus mi a gravida. Cras eleifend ligula eu nunc posuere vulputate.
060.                Donec vitae risus quis leo facilisis auctor. Pellentesque habitant morbi tristique
061.                senectus et netus et malesuada fames ac turpis egestas.</p>
062.            <p class="tags">
063.                <asp:Repeater ID="Tags" runat="server">
064.                    <HeaderTemplate>
065.                        <asp:Literal ID="TagsLiteral" runat="server" Text="Tags" />
066.                    </HeaderTemplate>
067.                    <ItemTemplate>
068.                        <asp:HyperLink ID="tagLink" runat="server" />
069.                    </ItemTemplate>
070.                </asp:Repeater>
071.                  
072.            </p>
073.            <table class="callout">
074.                <tr>
075.                    <th>
076.                        <img src="App_Themes/FTI-OneSite/img/andreas.jpg">
077.                    </th>
078.                    <td>
079.                        <h3>
080.                            <a href="">Andreas Panayi</a></h3>
081.                        <p>
082.                            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce egestas sodales nibh.
083.                            Integer lectus purus, blandit nec tincidunt ut, hendrerit vel ipsum.</p>
084.                    </td>
085.                </tr>
086.            </table>
087.            <sfWeb:BlogCommentsList ID="commentsList" runat="server" ValidationGroup="commentInfo">
088.                <LayoutTemplate>
089.                    <asp:Repeater ID="commentsRepeater" runat="Server">
090.                        <HeaderTemplate>
091.                            <asp:PlaceHolder runat="server" ID="headerHolder">
092.                                <h2 class="comments">
093.                                    <asp:Literal ID="commentsCount" runat="server"></asp:Literal
094.                                    <asp:Literal ID="Literal1" runat="server" Text="Comments" />
095.                                </h2>
096.                            </asp:PlaceHolder>
097.                        </HeaderTemplate>
098.                        <ItemTemplate>
099.                            <!-- comment goes here -->
100.                            <sfWeb:CommentItem ID="authorCommentContainer" runat="server" CssClass="comment">
101.                                <Template>
102.                                    <p class="meta">
103.                                        <span class="name">
104.                                         <asp:HyperLink ID="webSiteLink" runat="server" Visible="false"></asp:HyperLink>
105.                                        <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="MMM dd, yyyy" />
106.                                        </span>
107.                                    </p>
108.                                  <asp:Label ID="text" runat="server"></asp:Label>
109.                                    <p class="right">
110.                                        <a href="">Reply</a></p>
111.                                </Template>
112.                            </sfWeb:CommentItem>
113.                        </ItemTemplate>
114.                        <FooterTemplate>
115.                        </FooterTemplate>
116.                    </asp:Repeater>
117.                    <%--<asp:PlaceHolder ID="moderationHolder" runat="server" Visible="false">
118.                        <p class="sf_commentMessage">
119.                            <asp:Literal ID="Literal2" runat="server" Text="CommentMessageModeration"></asp:Literal>
120.                        </p>
121.                    </asp:PlaceHolder>--%>
122.                    <h2>
123.                        Leave A Comment</h2>
124.                    <p>
125.                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce egestas sodales nibh.
126.                        Integer lectus purus, blandit nec tincidunt ut, hendrerit vel ipsum. Suspendisse
127.                        purus lectus, molestie viverra tristique sed, vulputate eget nunc.</p>
128.                     <fieldset>
129.                        <div class="col2">
130.                            <strong><asp:Label ID="Label2" runat="Server" Text="Name" AssociatedControlID="authorTxt"></asp:Label></strong><br />
131.                            <asp:TextBox ID="authorTxt" runat="server" size="30"></asp:TextBox>
132.                            <asp:RequiredFieldValidator runat="server" ID="authorVal" ControlToValidate="authorTxt"
133.                                ErrorMessage="NameEmpty" Display="dynamic" CssClass="sf_commentsValidator"></asp:RequiredFieldValidator>
134.                        </div><div class="col2">
135.                            <strong><label for="email">Email</label></strong><br />
136.                            <asp:TextBox ID="emailTxt" runat="server" size="30"></asp:TextBox>
137.                            <asp:RegularExpressionValidator runat="server" ID="emailVal" ControlToValidate="emailTxt"
138.                                ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="InvalidEmail"
139.                                Display="dynamic" CssClass="sf_commentsValidator"></asp:RegularExpressionValidator>
140.                        </div><div class="clear"></div><br />
141.                          
142.                         <div class="col2">
143.                            <asp:Label ID="Label4" runat="Server" Text="Web Site" AssociatedControlID="webSiteTxt" Visible="false" ></asp:Label>
144.                            <asp:TextBox ID="webSiteTxt" runat="server" size="30" Visible="false" Text="www.google.com" ></asp:TextBox>
145.                        </div>
146.                        <div class="col2">
147.                             <asp:DropDownList ID="ddlPractice" runat="server" AutoPostBack="true">
148.                        </asp:DropDownList>
149.                        </div><div class="col2">
150.                            <asp:DropDownList ID="ddlService" runat="server" Enabled="false" Width="200px">
151.                        </asp:DropDownList>
152.                        </div><div class="clear"></div><br />
153.                          
154.                         <asp:Label ID="Label1" runat="Server" Text="Comment" AssociatedControlID="commentTxt"></asp:Label><br />
155.  
156.                        <a 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;'>
157.                                Formatting options</a>
158.                            <telerik:RadEditor runat="server" ID="commentTxt" ToolsFile="~/Sitefinity/ControlTemplates/Blogs/ToolsFile.xml"
159.                                EnableEmbeddedSkins="True" Skin="Default" Width="100%" EditModes="Design">
160.                            </telerik:RadEditor>
161.                              
162.                            <asp:RequiredFieldValidator runat="server" ID="contentVal" ControlToValidate="commentTxt"
163.                            ErrorMessage="<CommentEmpty" Display="dynamic" ValidationGroup="commentInfo"
164.                            CssClass="sf_commentsValidator">
165.                        <strong>Message text is required</strong>
166.                        </asp:RequiredFieldValidator>
167.                          
168.                        <sfWeb:SpamProtector ID="spamProtector" runat="server" CssClass="commentsValidator hide"
169.                            enableautobotdiscovery="true" enablehiddentextboxstrategy="true" hiddentextboxerrormessage="Hidden TextBox has some text in it!"
170.                            HiddenTextBoxLabel="Do not fill this textbox!" hiddentextboxlabelcssclass="hide"
171.                            hiddentextboxinputcssclass="hide" enablemintimeoutstrategy="true" MinTimeout="2"
172.                            mintimeouterrormessage="Submission too fast!" />
173.                        <p class="center">
174.                            <asp:Button ID="submitBtn" runat="server" Text="PostThisComment" CssClass="sf_commentSubmit" /></p>
175.                    </fieldset>
176.                </LayoutTemplate>
177.            </sfWeb:BlogCommentsList>
178.        </div>
179.    </div>
180.</div>

Thanks & Regards,
Pravat Sharma

Posted by Community Admin on 15-Jun-2011 00:00

Hi Pravat,

Go to Blogs module and from there you can create a custom field. Your field should be of type Multiple choice.
Then populate the choices and save the field. It will appear for each content item ( blog post).
After that you can modify BlogPosts widget templates and add your field using Design >> Widget templates or the Control Designer(when you open the control for editing ).

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-Jun-2011 00:00

Hi Ivan,
            Thanks for your reply.
If i will create a custom field then how can i bind the drop downlist ? My requirement is, dropdownlist will fill from the database and  according to the first dropdown list selection, second dropdown list will fill. I have done these by using custom class. 

But my issue is , how can i save the selected value in database along with 'Name' , 'Email' and 'Comment' on post this comment click?

Thanks & Regards,
Pravat Sharma

Posted by Community Admin on 15-Jun-2011 00:00

Hello Pravat,

You can create a control that inherits from ChoiceField and implement your logic for binding. Check this thread.

Best wishes,
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 20-Jun-2011 00:00

Hi Ivan,
Tried implementing the code for BlogCommentList....
Please let me know as I get an error of 'A required control was not found in the template for "~/Sitefinity/ControlTemplates/Blogs/Custom_ContentViewSingleItem.ascx". The control must be assignable form type "System.Web.UI.WebControls.Repeater" and must have ID "commentsRepeater".'
Here is a look at the cs:

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/Custom_ContentViewSingleItem.ascx";
           
       


        protected override void InitializeControls(Control controlContainer)
       
            base.InitializeControls(controlContainer);

            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;
            //if (this.RequiredVal != null)
            //    this.RequiredVal.ValidationGroup = valGroup;
            this.SubmitButton.ValidationGroup = valGroup;
            if (this.SpamProtector != null)
           

           
       

        protected void SubmitButton_Command(object sender, CommandEventArgs e)
       
            base.SubmitButton_Command(sender, e);
       

   

The HTML of the ASCX is:

<div class="wrap">
    <div id="section">
        <h1>
            <asp:HyperLink ID="fullContent1" runat="server">
                <asp:Literal ID="Title" runat="server"></asp:Literal>
            </asp:HyperLink>
        </h1>
        <div class="meta">
            <p>
                <asp:Literal ID="Literal2" runat="server" Text="By "></asp:Literal>
                <asp:HyperLink ID="postedBy" runat="server">
                    <asp:Literal ID="Author" runat="server"></asp:Literal>
                </asp:HyperLink>
                |
                <telerik:DateTimeLiteral runat="server" ID="Publication_Date" DateFormatString="MMM dd, yyyy">
                </telerik:DateTimeLiteral>
                <asp:HyperLink ID="Category" runat="server" />
            </p>
        </div>
        <div class="article">
            <p>
                <asp:Panel ID="pnlContent" runat="server" CssClass="article">
                    <asp:Literal ID="content" runat="server"></asp:Literal>
                </asp:Panel>
            </p>
            
            <p class="tags">
                <asp:Repeater ID="Tags" runat="server">
                    <HeaderTemplate>
                        <asp:Literal ID="TagsLiteral" runat="server" Text="Tags" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:HyperLink ID="tagLink" runat="server" />
                    </ItemTemplate>
                </asp:Repeater>
                
            </p>
            <table class="callout">
                <tr>
                    <th>
                        <img src="App_Themes/FTI-OneSite/img/andreas.jpg">
                    </th>
                    <td>
                        <h3>
                            <a href="">Andreas Panayi</a></h3>
                        <p>
                            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce egestas sodales nibh.
                            Integer lectus purus, blandit nec tincidunt ut, hendrerit vel ipsum.</p>
                    </td>
                </tr>
            </table>
            <sfWeb:BlogCommentsList ID="commentsList" runat="server" ValidationGroup="commentInfo">
                <LayoutTemplate>
                    <asp:Repeater ID="commentsRepeater" runat="Server">
                        <HeaderTemplate>
                            <asp:PlaceHolder runat="server" ID="headerHolder">
                                <h2 class="comments">
                                    <asp:Literal ID="commentsCount" runat="server"></asp:Literal>&nbsp;
                                    <asp:Literal ID="Literal1" runat="server" Text="Comments" />
                                </h2>
                            </asp:PlaceHolder>
                        </HeaderTemplate>
                        <ItemTemplate>
                            <!-- comment goes here -->
                            <sfWeb:CommentItem ID="authorCommentContainer" runat="server" CssClass="comment">
                                <Template>
                                    <p class="meta">
                                        <span class="name">
                                         <asp:HyperLink ID="webSiteLink" runat="server" Visible="false"></asp:HyperLink>
                                        <telerik:DateTimeLiteral ID="commentDateLiteral" runat="server" DateFormatString="MMM dd, yyyy" />
                                        </span>
                                    </p>
                                  <asp:Label ID="text" runat="server"></asp:Label>
                                    <p class="right">
                                        <a href="">Reply</a></p>
                                </Template>
                            </sfWeb:CommentItem>
                        </ItemTemplate>
                        <FooterTemplate>
                        </FooterTemplate>
                    </asp:Repeater>
                    <%--<asp:PlaceHolder ID="moderationHolder" runat="server" Visible="false">
                        <p class="sf_commentMessage">
                            <asp:Literal ID="Literal2" runat="server" Text="CommentMessageModeration"></asp:Literal>
                        </p>
                    </asp:PlaceHolder>--%>
                    <h2>
                        Leave A Comment</h2>
                    <p>
                        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce egestas sodales nibh.
                        Integer lectus purus, blandit nec tincidunt ut, hendrerit vel ipsum. Suspendisse
                        purus lectus, molestie viverra tristique sed, vulputate eget nunc.</p>
                     <fieldset>
                        <div class="col2">
                            <strong><asp:Label ID="Label2" runat="Server" Text="Name" AssociatedControlID="authorTxt"></asp:Label></strong><br />
                            <asp:TextBox ID="authorTxt" runat="server" size="30"></asp:TextBox>
                            <asp:RequiredFieldValidator runat="server" ID="authorVal" ControlToValidate="authorTxt"
                                ErrorMessage="NameEmpty" Display="dynamic" CssClass="sf_commentsValidator"></asp:RequiredFieldValidator>
                        </div><div class="col2">
                            <strong><label for="email">Email</label></strong><br />
                            <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="InvalidEmail"
                                Display="dynamic" CssClass="sf_commentsValidator"></asp:RegularExpressionValidator>
                        </div><div class="clear"></div><br />
                       
                         <div class="col2">
                            <asp:Label ID="Label4" runat="Server" Text="Web Site" AssociatedControlID="webSiteTxt" Visible="false" ></asp:Label>
                            <asp:TextBox ID="webSiteTxt" runat="server" size="30" Visible="false" Text="www.google.com" ></asp:TextBox>
                        </div>
                        <div class="col2">
                             <asp:DropDownList ID="ddlPractice" runat="server" AutoPostBack="true">
                        </asp:DropDownList>
                        </div><div class="col2">
                            <asp:DropDownList ID="ddlService" runat="server" Enabled="false" Width="200px">
                        </asp:DropDownList>
                        </div><div class="clear"></div><br />
                       
                         <asp:Label ID="Label1" runat="Server" Text="Comment" AssociatedControlID="commentTxt"></asp:Label><br />

                        <a 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;'>
                                Formatting options</a>
                            <telerik:RadEditor runat="server" ID="commentTxt" ToolsFile="~/Sitefinity/ControlTemplates/Blogs/ToolsFile.xml"
                                EnableEmbeddedSkins="True" Skin="Default" Width="100%" EditModes="Design">
                            </telerik:RadEditor>
                            
                            <asp:RequiredFieldValidator runat="server" ID="contentVal" ControlToValidate="commentTxt"
                            ErrorMessage="<CommentEmpty" Display="dynamic" ValidationGroup="commentInfo"
                            CssClass="sf_commentsValidator">
                        <strong>Message text is required</strong>
                        </asp:RequiredFieldValidator>
                        
                        <sfWeb:SpamProtector ID="spamProtector" runat="server" CssClass="commentsValidator hide"
                            enableautobotdiscovery="true" enablehiddentextboxstrategy="true" hiddentextboxerrormessage="Hidden TextBox has some text in it!"
                            HiddenTextBoxLabel="Do not fill this textbox!" hiddentextboxlabelcssclass="hide"
                            hiddentextboxinputcssclass="hide" enablemintimeoutstrategy="true" MinTimeout="2"
                            mintimeouterrormessage="Submission too fast!" />
                        <p class="center">
                            <asp:Button ID="submitBtn" runat="server" Text="PostThisComment" CssClass="sf_commentSubmit" /></p>
                    </fieldset>
                </LayoutTemplate>
            </sfWeb:BlogCommentsList>
        </div>
    </div>
</div>

Please help me in this as this is really urgent.

Your prompt response would be highly appreciated.

Regards,
Pravat Sharma

Posted by Community Admin on 20-Jun-2011 00:00

Hello Pravat,

As far as I see this code is for Sitefinity 3.x. Inside the template, you should replace the default BlogCommentsList with the custom one you created.

Best wishes,
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 20-Jun-2011 00:00

Hi,

Please can you let me know how can I register the control from App_Code to the page and replace the BlogCommentsList.

Thanks for all your help....

Posted by Community Admin on 20-Jun-2011 00:00

Hello Pravat,

Here is a  good article on MSDN that shows how to register a tag prefix and respectively add a custom control inside the template.

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 21-Jun-2011 00:00

Hi Ivan,

Thanks a ton. We have mapped custom comment list to by replacing the BlogCommentList.

But now as per the code given earlier, when I try to save the data it saves, but all the fields are saved empty.

Also, if I can get the ID of the saved comment on submit button click, this would help in saving my custom drop down boxes in my custom tables with the reference to the ID of the comment.

Regards,
Pravat Sharma

Posted by Community Admin on 21-Jun-2011 00:00

Hello Pravat,

Here are two useful thread where I showed how to get access to all fields of the contorol


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

This thread is closed