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

Forums / Developing with Sitefinity / Using Blog Comments on a Custom Control

Using Blog Comments on a Custom Control

20 posts, 0 answered
  1. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    14 Oct 2010
    Link to this post
    Hi,

    I am currently creating a custom control on our website which needs to use Blog Comments. I am new to Sitefinity, and have used the code from the ContentViewSingleItem.ascx to achieve this task.

    The following line is giving me an error saying "The resource object with key 'Comments' was not found."

    <asp:Literal ID="Literal1" runat="server" Text="<%$Resources:Comments %>" />

    What do I need to do to solve this issue?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Oct 2010
    Link to this post
    Hi Rosco,

    You should have a App_LocalResources folder in the same level as your control resides. In this folder you should have resource file with this key. You can take a look at Resources and Localization in ASP.NET 2.0

    All the best,
    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
  3. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    21 Oct 2010
    Link to this post
    Thanks for that. My next question is, how do I reference asp.net controls which are nested inside an <sfWeb:BlogCommentsList> tag?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Oct 2010
    Link to this post
    Hi Rosco,

    You can get them from the controls collection of BlogCommentsList or create a custom control that inherits from BlogCommentsList and use the container. You could check this post.

    All the best,
    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
  5. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    21 Oct 2010
    Link to this post
    Thanks for the prompt reply. Does this resource file need to have a specific name?
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    22 Oct 2010
    Link to this post
    Hello Rosco,

    You should have the same resource key a resx file in your App_LocalResource folder.

    All the best,
    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
  7. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    25 Oct 2010
    Link to this post
    Thanks,

    Where can I find more information on how this works? I have managed to build my control without receiving any errors on the page, but I am still puzzled on how blog comments actually works. Where do they get stored, and how can I display comments on my custom control for a particular page on our website. Also, how do I post a blog comment? I haven't managed to find any C# examples on what happens on the backend. Any help will be greatly appreciated.
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    25 Oct 2010
    Link to this post
    Hi Rosco,

    You can take a look at Blogs API and Comments API. All data for the Generic Content providers is saved to the database.

    All the best,
    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
  9. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    26 Oct 2010
    Link to this post
    Thanks for that. I am now trying to bind my "commentsRepeater" with the data from the contentManager.GetContent() list. However, I am receiving a null reference exception when trying the following code:

    Repeater commentsRepeater = (Repeater)this.commentsList.FindControl("commentsRepeater");

    CommentsList is the name of the BlogCommentsList control.
  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Oct 2010
    Link to this post
    Hi Rosco,

    commentsRepeater does not exist inside the control commentsList or it cannot be find inside controls collection and you should search for it recursively. If you create  a custom class that inherits from CommentsList you can find the control by making a reference to the container.

    protected virtual Repeater CommentsRepeater
       {
           get { return base.Container.GetControl<Repeater>("commentsRepeater", true); }
       }


    Regards,
    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
  11. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    28 Oct 2010
    Link to this post

    Thanks, I managed to use a recursive function to retrieve the control. Now, I am trying to display the comments for the current page. Please take a look at http://www.magnetism.co.nz/blog/roshan/10-10-28/Tweet_it_Like_it_Digg_it.aspx

    We plan to replace the comments area with a custom control I am creating. What I want to do is allow the user to make a comment on ANY page on our website. It will need to be stored in the database based on the URL if possible, but I haven't seen anything like this in the API. Then, when the page loads, it can retrieve the comments by passing the URL as a reference. Here is the code I have used to create comments when submitBtn is clicked:

    TextBox comments = (TextBox)FindControlRecursive(this.commentsList, "commentTxt");
    TextBox author = (TextBox)FindControlRecursive(this.commentsList, "authorTxt");
    TextBox email = (TextBox)FindControlRecursive(this.commentsList, "emailTxt");
    TextBox website = (TextBox)FindControlRecursive(this.commentsList, "websiteTxt");
    Button btn = (Button)sender;
    ContentManager cm = new ContentManager();
    IList contentItems = cm.GetContent();
    if (contentItems.Count > 0)
    {
        IContent content = cm.GetContent(((IContent)contentItems[0]).ID);
        IComment comment = cm.CreateComment(content);
        comment.Text = comments.Text;
        comment.Author = author.Text;
        comment.Email = email.Text;
        comment.WebSite = website.Text;
        cm.SaveComment(comment);
    }

    This doesn't seem to submit anything to the database. Here is my code to retrieve and display comments:

    ContentManager cm = new ContentManager();
    IList contentItems = cm.GetContent();           
    this.commentsCount.Text = contentItems.Count.ToString();
    Repeater commentsRepeater = (Repeater)FindControlRecursive(this.commentsList, "commentsRepeater");
    commentsRepeater.DataSource = contentItems;
    commentsRepeater.DataBind();

    Notice I have set the commentsCount text. This always displays 66 but we have checked our database and there are only 30 comments. I am also unsure what to add to the aspx file in order to display the comments data inside the repeater.

  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    01 Nov 2010
    Link to this post
    Hello Rosco,

    Your code gets the content items, not the comments - IList contentItems = cm.GetContent(); This method gets the content item, not the comments. Then you bind the repeater to a list of these content items.

    You should get the comments by using GetComments(Guid itemId)


    Greetings,
    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
  13. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    08 Nov 2010
    Link to this post
    Hi Ivan,

    Perhaps it might help if you could provide a bit of sample code for me to use here. I am not sure what ID I need to pass to retrieve the comments for the current page.
  14. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Nov 2010
    Link to this post
    Hi Rosco,

    Please take a look at the articles below



    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
  15. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    10 Nov 2010
    Link to this post
    Hi Ivan,

    I'm still confused with how this works. What exactly is a content item? I see the example here only retrieves the first content item http://www.sitefinity.com/help/developer-manual/comments-create.html when creating a comment. Also, how does it know that we are creating a comment for a specific page on our website?

    The comments functionality is intended to work with any page on our website, not just with blogs.

    Please assist me on where to start with this. I have seen that each page has a unique guid provided by the Generic Content object. Do I need to use this in some way?
  16. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    10 Nov 2010
    Link to this post
    Hi Rosco,

    What is IContent - All content objects generated by Generic Content based modules (such as blog posts, news items and so on) implement IContent interface. By taking advantage of this common interface all Generic Contentent based module are able to share various functionality, such as tagging, categorizing and commenting. The method - CreateComment uses IContent as a parameter where you should pass the ID of the IContent item for which you are creating a comment.

    Regards,
    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
  17. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    12 Nov 2010
    Link to this post

    I am receiving the following error:

    c:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\f52f3550\a1903490\App_Web_social-connector.ascx.e6437d6c.chky2dpn.0.cs(447): error CS0122: 'Telerik.Cms.Engine.WebControls.CommentItem.CommentContainer' is inaccessible due to its protection level

    This error occurs when I insert the following code into the ashx file.

    <!--show user comments first-->
    <sfWeb:CommentItem ID="anoncommentcontainer" runat="server">
        <Template>
            <div class="commenter-info-wrap">
                <div class="commenter-info-top">
                </div>
                <div class="commenter-info">
                    <a href="#">
                        <asp:Literal ID="authorname" runat="server" Text='<%#Eval("Author") %>'></asp:Literal></a>
                    <p>
                        <telerik:datetimeliteral id="commentdate" runat="server" dateformatstring="" />
                    </p>
                    <a href="#">Reply to this post</a>
                </div>
                <div class="commenter-info-bottom">
                </div>
            </div>
            <div class="commenter-comment-tip">
            </div>
            <div class="commenter-comment-wrap">
                <div class="commenter-comment-top">
                </div>
                <div class="commenter-comment">
                    <p>
                        <asp:Literal ID="commenttext" runat="server" Text='<%#Eval("Text") %>'></asp:Literal></p>
                </div>
                <div class="commenter-comment-bottom">
                </div>
            </div>
        </Template>
    </sfWeb:CommentItem>
  18. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Nov 2010
    Link to this post
    Hello Rosco,

    1. The error is thrown from social-connector.ascx control. If this code is not part of it, please check the social-connector.ascx control.

    2. Try removing the Eval to see if the error will disappear. The error says that you are trying to use the private controls container of CommentsList control - CommentContainer somewhere in your code.

    Kind regards,
    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
  19. Rosco
    Rosco avatar
    13 posts
    Registered:
    30 Oct 2008
    18 Nov 2010
    Link to this post
    Hi,

    All seems to be going well. I have managed to display and create comments with my control. Now, I wish to grab the current blog page title. However, using the following code seems to return the title of the parent blog template:

    string pageTitle = Page.Title;

    Am I able to grab the blog page title programmatically?
  20. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    18 Nov 2010
    Link to this post
    Hi Rosco,

    The hierarchy you have is as follows

    1. You have a comment item. The parent of the comment item is your content item.

    2. The content item is your blog post.

    3. The parent of the content item is the blog

    Content content = cm.GetContent(((IContent)contentItems[0]).ID); returns the content item, so you can call GetMetaData("Title").ToString().

    if you call content.parent you will get an instance of the IBlog object

    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
Register for webinar
20 posts, 0 answered