More in this section

Forums / Developing with Sitefinity / News for Commnet

News for Commnet

15 posts, 0 answered
  1. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    01 Feb 2008
    Link to this post

    Sitefinity Support,

    I am just wondering if you could give me some idea how to implement comments for News for your news module in Sitefinity. The reason I am asking is because we want end user be able to comment on the news so that we can get more hits on the web site and keep advertisers happy.

    I only need a text box and submit button on the news detail page.

    Please help me
    Thanks
    Tim

  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    04 Feb 2008
    Link to this post
    Hi Tim,

    You can create your own control for comments that inherits the CommentsList public class:

    namespace Comments 
        public class CommentsListExtender : CommentsList 
        { 
            public CommentsListExtender() 
            { 
            } 
     
            public override string ProviderName 
            { 
                get 
                { 
                    if (string.IsNullOrEmpty(base.ProviderName)) 
                        return NewsManager.DefaultContentProvider; 
     
                    return base.ProviderName; 
                } 
                set 
                { 
                    base.ProviderName = value; 
                } 
            } 
     
            protected override void CreateChildControls() 
            { 
                base.Moderation = false
     
                base.CreateChildControls(); 
            } 
        } 

    After that, add the following line in <toolboxControls> section of the application Web.config to display the control in the "Add Controls" toolbox:

    <add name="CommentsListExtender" section="Comments" type="Comments.CommentsListExtender, App_Code" /> 

    Also, you need to copy the comments list template and resource file (~/Sitefinity/ControlTemplates/Blogs/CommentsList.ascx and
    ~/Sitefinity/ControlTemplates/Blogs/App_LocalResources/CommentsList.ascx.resx) to the News folder.

    Finally,
    in the property window of the CommentsList control, you should set the ParentID property to specify the id of the news item that will be commented.

    Hope this helps.


    All the best,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    04 Feb 2008
    Link to this post

    Sitefinity support,

    Thanks for getting back to me.  I am just wondering if I need to set the ParentID property to specify the id of the EVERY news item that will be commented. If that's the case, I don't think it's going to work for me because we upload a lot news items everyday. I am looking for the solution which integrated the comment control into news module so that it's automatically tied the comment into the news in the CMS system instead of manually specifying the each news item ID into the comment list.

    Hope it makes sense to you
    Tim

  4. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    04 Feb 2008
    Link to this post
    Hello Tim,

    You could modify the CommentsLisrExtender public control as follows:

    namespace Comments 
        public class CommentsListExtender : CommentsList 
        { 
            public CommentsListExtender() 
            { 
            } 
     
            public override string ProviderName 
            { 
                get 
                { 
                    if (string.IsNullOrEmpty(base.ProviderName)) 
                        return NewsManager.DefaultContentProvider; 
     
                    return base.ProviderName; 
                } 
                set 
                { 
                    base.ProviderName = value; 
                } 
            } 
     
            protected override void CreateChildControls() 
            { 
                object obj = this.Context.Items["ArticleID"]; 
                if (obj != null
                    this.articleId = (Guid)obj; 
                if (this.articleId == Guid.Empty) 
                    return
     
                base.ParentID = articleId; 
                base.Moderation = false
     
                base.CreateChildControls(); 
            } 
     
            private Guid articleId; 
        } 

    In this way it will get the ID of the selected news item dynamically .

    Sincerely yours,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    04 Feb 2008
    Link to this post
    Sitefinity Team,

    I got following error when I tried to run it:


    A required control was not found in the template for "Telerik.Cms.Engine.WebControls.CommentsListContainer". The control must be assignable form type "System.Web.UI.WebControls.Repeater" and must have ID "commentsRepeater".

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: A required control was not found in the template for "Telerik.Cms.Engine.WebControls.CommentsListContainer". The control must be assignable form type "System.Web.UI.WebControls.Repeater" and must have ID "commentsRepeater".

    Source Error:

    Line 57:             base.Moderation = false;
    Line 58:
    Line 59: base.CreateChildControls();
    Line 60: }
    Line 61:

    Source File: e:\backup\web\websmart\websmart31sp2\App_Code\CommentsListExtender.cs    Line: 59

    Stack Trace:

    [HttpException (0x80004005): A required control was not found in the template for "Telerik.Cms.Engine.WebControls.CommentsListContainer". The control must be assignable form type "System.Web.UI.WebControls.Repeater" and must have ID "commentsRepeater".]
    Telerik.Cms.Web.UI.GenericContainer`1.FindControl(Type requiredType, String id, Boolean required) +234
    Telerik.Cms.Web.UI.GenericContainer`1.FindRequiredControl(String id) +66
    Telerik.Cms.Engine.WebControls.CommentsListContainer.get_CommentsRepeater() +34
    Telerik.Cms.Engine.WebControls.CommentsList.CreateChildControls() +601
    Comments.CommentsListExtender.CreateChildControls() in e:\backup\web\websmart\websmart31sp2\App_Code\CommentsListExtender.cs:59
    System.Web.UI.Control.EnsureChildControls() +87
    System.Web.UI.Control.PreRenderRecursiveInternal() +50
    System.Web.UI.Control.PreRenderRecursiveInternal() +170
    System.Web.UI.Control.PreRenderRecursiveInternal() +170
    System.Web.UI.Control.PreRenderRecursiveInternal() +170
    System.Web.UI.Control.PreRenderRecursiveInternal() +170
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

  6. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    05 Feb 2008
    Link to this post
    Hello Tim,

    As I have already mentioned in my first post, you need to copy the CommentsList template (~/Sitefinity/ControlTemplates/Blogs/CommentsList.ascx) and the corresponding resource file (~/Sitefinity/ControlTemplates/Blogs/App_LocalResources/CommentsList.ascx.resx) from Blogs to News folder.
    This should solve the problem.

    Regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    05 Feb 2008
    Link to this post
    FYI,

    I did copy them into news folder.

    Tim
  8. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    05 Feb 2008
    Link to this post
    Hi Tim,

    The only reason for this exception is that it cannot find the necessary template (~/Sitefinity/ControlTemplates/News/CommentsList.ascx) and tries to load the default one that has no implementation. So check once again if you have CommentsList.ascx template in the ~/Sitefinity/ControlTemplates/News/ folder. If everything is properly set, try to specify the path to the template explicitly. To achieve this, open the property window of the CommentsListExtender control and set the TemplateUrl property in the Appearance section to ~/Sitefinity/ControlTemplates/News/CommentsList.ascx.

    Also, pay attention to the fact that
    CommentsListExtender control is a public control and the right folder is ~/Sitefinity/ControlTemplates/News/  and not ~/Sitefinity/Admin/ControlTemplates/News/.

    If this does not help you solve the issue, please send us your project and database to figure out what else is wrong.


    Kind regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    06 Feb 2008
    Link to this post
    Sitefinity support,

    I am just wondering if it's because I didn't  use default news provider. So far I did everything based on your posts and still doesn't work.

    Anyway thanks for your help

    Tim
  10. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    06 Feb 2008
    Link to this post
    Hello Tim,

    For example if the custom provider is Breaking_News, copy the News folder in ~/Sitefinity/ControlTemplates/  and rename it to Breaking_News. The newly created Breaking_News folder should contain all templates for news public controls including CommentsList.ascx template. Also in the property window of the comments control, you need to set ProviderName property to Breaking_News.

    Hope this helps solve the problem.

    Kind regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. Tim
    Tim avatar
    156 posts
    Registered:
    23 Sep 2007
    06 Feb 2008
    Link to this post
    Sitefinity Support,

    It works now.

    Thanks
    Tim
  12. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    22 Apr 2008
    Link to this post
    hi, I'm not sure if this was an older version, but I used the code above and got a cast error on this line:

    object obj = this.Context.Items["ArticleID"];


    I changed it to this:

    object obj = ((Telerik.Web.UrlRewriteData)this.Context.Items["ArticleID"]).Data;


    and it works now! so if you're getting casting errors see if that works for you
  13. SelAromDotNet
    SelAromDotNet avatar
    912 posts
    Registered:
    18 Jul 2012
    22 Apr 2008
    Link to this post
    oops, doing that casting on an empty page will throw a null reference error! object should still be cast, but not until AFTER you check for null :)

    object obj = this.Context.Items["ArticleID"];
    if (obj != null)
        this.articleId = (Guid)((Telerik.Web.UrlRewriteData)obj).Data;
    if (this.articleId == Guid.Empty)
        return;

    THAT should do it

  14. Szymon
    Szymon avatar
    22 posts
    Registered:
    04 Jan 2008
    14 Jul 2008
    Link to this post
    Actually in the latest version (3.2 SP2) the context item is called "NewsItem" by default instead of "ArticleID". Tou can either change this on the newsView control or in the code.

    Hope this helps,
    -Szymon
  15. Pepi
    Pepi avatar
    981 posts
    Registered:
    31 Jan 2017
    15 Jul 2008
    Link to this post
    Hi Josh and Szymon,

    ArticleID key is used in the obsolete News and Blogs controls. If you need to identify the selected single item in the old NewsList and PostList controls, use the following code:

    object obj = this.Context.Items["ArticleID"]; 
    if (obj != null
        this.articleId = (Guid)((Telerik.Web.IUrlRewriteData)obj).Data; 
    if (this.articleId == Guid.Empty) 
        return

    Regarding the new News View control, Szymon is right that the default value is NewsItem.

    Hope this helps.

    Regarding
    Kind regards,
    Pepi
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Register for webinar
15 posts, 0 answered