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

Forums / General Discussions / Show single forum

Show single forum

26 posts, 0 answered
  1. Brian Crosby
    Brian Crosby avatar
    29 posts
    Registered:
    02 Jan 2006
    14 Apr 2010
    Link to this post
    Is there a way to only display one forum on a page? I want different parts of the site to only see the forum that is applicable to them.

    Cheers,

    Brian
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Apr 2010
    Link to this post
    Hi Brian Crosby,

    You have to implement a custom control where you could pass the ID of the forum that you want to show. You could inherit from SingleForum control, add a public property for the forum ID( it could be done with web editor as well). You need to implement logic for editing and creating new threads

    sample code

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Forums.WebControls;
     
    /// <summary>
    /// Summary description for SingleForumCustom
    /// </summary>
    public class SingleForumCustom : SingleForum
    {
        public SingleForumCustom()
        {
        }
     
        protected override void CreateChildControls()
        {
            this.selectedForumID = SetSingleforumID;
            base.CreateChildControls();
        }
     
        public Guid SetSingleforumID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }
        private Guid id;
    }

    You have to implement commands for  NewThreadButton1 and BackToForumsButton1

    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.
  3. Brian Crosby
    Brian Crosby avatar
    29 posts
    Registered:
    02 Jan 2006
    15 Apr 2010
    Link to this post
    Thanks for that quick replay. How do I go about having a dropdown box with the possible forums instead of just a text box?

    Cheers,

    Brian
  4. Brian Crosby
    Brian Crosby avatar
    29 posts
    Registered:
    02 Jan 2006
    15 Apr 2010
    Link to this post
    Also, how do I use the new control?

    I added <add name="Single Forum Custom" section="Forums" type="SingleForumCustom"/> to the web.config inside toolboxcontrols and when I edit a page it says Error loading control: Could not load type 'SingleForumCustom' from assembly 'telerik.cms, version 3.7.2022.2'.
    I added the new control in app_code. I didn't nest it in a namespace so it should use the base namespace.

    What am I missing?

  5. Brian Crosby
    Brian Crosby avatar
    29 posts
    Registered:
    02 Jan 2006
    15 Apr 2010
    Link to this post
    I moved the control to a separate library and now it works fine. I tried to create a control designer for it but it isn't saving the values. Can you help me out with that?

    Imports System.Web.UI.WebControls
    Imports Telerik.Forums
     
    Public Class SingleForumDesigner
        Inherits Telerik.Framework.Web.Design.ControlDesigner
     
        ''' <summary>
        ''' Gets or sets the path to a custom layout template for the control.
        ''' </summary>
        ''' <value></value>
        Public Overrides Property LayoutTemplatePath() As String
            Get
                Return "~/UserControls/ControlDesigners/ForumSelector.ascx"
            End Get
            Set(ByVal value As String)
                MyBase.LayoutTemplatePath = value
            End Set
        End Property
     
        ''' <summary>
        ''' Initializes all controls instantiated in the layout container. This method is called
        ''' at appropriate time for setting initial values and subscribing for events of layout controls.
        ''' </summary>
        ''' <param name="viewContainer">The control that will host the current view.</param>
        Protected Overrides Sub InitializeControls(ByVal viewContainer As System.Web.UI.Control)
            If Not Page.IsPostBack Then
                Dim forumManager As New ForumManager()
     
                ForumList.DataSource = forumManager.GetForums(True)
                ForumList.DataTextField = "Name"
                ForumList.DataValueField = "ID"
                ForumList.DataBind()
     
                For Each item As ListItem In ForumList.Items
                    If item.Value = CType(DesignedControl, SingleForumCustom).SingleForumID.ToString() Then
                        item.Selected = True
                    End If
                Next
     
                'For Each forum As IForum In forumManager.GetForums(False)
                '    ForumList.Items.Add(New ListItem(forum.Name, forum.ID.ToString()))
                'Next
     
            End If
        End Sub
     
        ''' <summary>
        ''' This method is called by the ControlEditor when the component is about to be saved.
        ''' </summary>
        Public Overrides Sub OnSaving()
            If Not String.IsNullOrEmpty(ForumList.SelectedValue) Then
                CType(DesignedControl, SingleForumCustom).SingleForumID = New Guid(ForumList.SelectedValue)
            End If
        End Sub
     
        ''' <summary>
        ''' Gets a reference to the DropDownList control contained in the LayoutTemplatePath template.
        ''' </summary>
        Protected ReadOnly Property ForumList() As DropDownList
            Get
                Return MyBase.Container.GetControl(Of DropDownList)("forumList", True)
            End Get
        End Property
     
    End Class
     
    Imports System
    Imports Telerik.Forums.WebControls
     
    ''' <summary>
    ''' Custom implementation of SingleForum that allows choosing the forum to display.
    ''' </summary>
    <Telerik.Framework.Web.Design.ControlDesigner(GetType(SingleForumDesigner))> _
    Public Class SingleForumCustom
        Inherits SingleForum
     
        Private forumId As Guid
     
        ''' <summary>
        ''' Overriden. Called to populate the child control hierarchy. This is the main
        ''' method to render the control's markup, since it is a CompositeControl and contains
        ''' child controls.
        ''' </summary>
        Protected Overrides Sub CreateChildControls()
            selectedForumID = SingleForumID
     
            MyBase.CreateChildControls()
        End Sub
     
        Public Property SingleForumID() As Guid
            Get
                Return Me.forumId
            End Get
            Set(ByVal value As Guid)
                Me.forumId = value
            End Set
        End Property
    End Class

    Here's the control designer aspx

    <%@ Control Language="VB" %>
    <div class="ctrlProps">
        <div class="ctrlContent">
            <h3>Select Forum</h3>
            <asp:DropDownList ID="forumList" runat="server"></asp:DropDownList>
        </div>
    </div>
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    15 Apr 2010
    Link to this post
    Hi Brian Crosby,

    You should have a property of the custom class for which you create the designer and set the value from the designer to this property.Anyway, the code below works at my end.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Forums.WebControls;
    using Telerik.Web.UI;
    using Telerik.Forums;
    using System.Collections;
    using Telerik.Framework.Web.Design;
     
    /// <summary>
    /// Summary description for SingleForumCustom
    /// </summary>
    ///
     
    [ControlDesignerAttribute("SingleForumControlDesigner, App_Code")]
    public class SingleForumCustom : SingleForum
    {
        public SingleForumCustom()
        {
        }
     
        protected override void CreateChildControls()
        {
            this.selectedForumID = SetSingleforumID;
            base.CreateChildControls();
        }
     
        public Guid SetSingleforumID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }
        private Guid id;
    }
     
    public class SingleForumControlDesigner : Telerik.Framework.Web.Design.ControlDesigner
    {
     
        public override string LayoutTemplatePath
        {
            get
            {
                return "~/CustomControls/SingleForumDesignerTempalate.ascx";
            }
     
        }
     
        protected override void InitializeControls(System.Web.UI.Control viewContainer)
        {
            base.InitializeControls(viewContainer);
        }
     
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
     
            if (Combo != null)
            {
                var manager = new ForumManager();
                IList allforums = manager.GetForums(true);
                RadComboBoxItem nullItem = new RadComboBoxItem("--SelecteItem--", string.Empty);
                Combo.Items.Add(nullItem);
                foreach (IForum forum in allforums)
                {
                    RadComboBoxItem item = new RadComboBoxItem(forum.Name, forum.ID.ToString());
                    Combo.Items.Add(item);
                }
     
                Combo.SelectedValue = ((SingleForumCustom)DesignedControl).SetSingleforumID.ToString();
            }
        }
        public override void OnSaving()
        {
            base.OnSaving();
            ((SingleForumCustom)DesignedControl).SetSingleforumID = new Guid(Combo.SelectedValue);
        }
     
     
        protected virtual RadComboBox Combo
        {
            get
            {
                return this.Container.GetControl<RadComboBox>("Combo1", 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.
  7. martin
    martin avatar
    36 posts
    Registered:
    30 Nov 2008
    02 Jul 2010
    Link to this post
    Hi Ivan,

    Is there any chance that you could put up files so that I can download them as I'm having differculty getting the above approach working

    Thanks
    Kieran
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    02 Jul 2010
    Link to this post
    Hi martin,

    Could you elaborate some more what the actual problem is, so I could try to help.

    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
  9. martin
    martin avatar
    36 posts
    Registered:
    30 Nov 2008
    05 Jul 2010
    Link to this post
    Hi Ivan

    I have a number of forums created, and want to display a specific forum on specific pages.  

    I see there is a single forum module built into Sitefinity. Can I use the singleforum module to get the functionality that I require. I have tried the above code but don't know where to place the code.

    Kieran

  10. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Jul 2010
    Link to this post
    Hello martin,

    The code provided in this thread is a custom control that inherits from SingleForum and extend its functionality. The new control gives you the ability to specify the forum/thread ID and display only this thread on a page by dropping the custom control on a page. You could add the code inside App_Code folder or create a custom class library and compile it to a dll.
    Using the built-in SingleForum control you could not set the id of a forum/thread. The SingleForum control can be used only with conjunction with Forums or Forum List controls.

    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
  11. martin
    martin avatar
    36 posts
    Registered:
    30 Nov 2008
    05 Jul 2010
    Link to this post
    Hi Ivan


    I have created a SingleForumCustom.cs file and place it into the App_Code Folder.

    I have tried to add this control in the Web.config
    <add name="Single Forum Custom" section="Forums" type="SingleForumCustom"/>
    But I to get the "Error Loading Control".

    Is there something I am missing.

    Kieran
  12. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Jul 2010
    Link to this post
    Hi martin,

    The type should contain the assembly name or the building folder.

    sample

    <add name="SingleForumCustom" section="Custom" type="SingleForumCustom, App_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
  13. martin
    martin avatar
    36 posts
    Registered:
    30 Nov 2008
    05 Jul 2010
    Link to this post
    Excellent stuff,

    Thanks Ivan
  14. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    06 Jul 2010
    Link to this post
    What would I inherit to select a single category?
  15. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    06 Jul 2010
    Link to this post
    Hi Kristian,

    Please elaborate some more about desired functionality. The sample above shows how the get single forum by ID, so in this case the category does not matter.

    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
  16. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    06 Jul 2010
    Link to this post
    I would like functionality similar to the way the forum list control works, but to only display one category of my choosing.

    Thanks,
    -Kristian
  17. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    07 Jul 2010
    Link to this post
    Hi Kristian,

    You can use

    GetForums(ICategory category, bool excludeHidden) - Get specific subset of all forums that belong to given category (with option to exculde hidden ones)
    GetForums(Guid categoryID, bool excludeHidden) - Get specific subset of all forums that belong to given category with specified ID (with option to exculde hidden ones)
    GetForumsUncategorized(bool excludeHidden) - Get all forums in the Forums module which do not belong to any category (with option to exculde hidden ones)

    You could take a look at Forums API Overview

    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
  18. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    08 Jul 2010
    Link to this post
    Cool Thanks, I have most of the functionality I need.

    How would I get the the total threads, latest post date, and latest post author?

    I can find total posts by using
    forum.Posts.Count.ToString();

    Not sure where to find the others.
  19. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Jul 2010
    Link to this post
    Hi Kristian,

    You can use manager.GetForums which will return you IList of all forums form where you can get the data you want to return. You will find samples and more description here -Finding Forums

    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
  20. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    08 Jul 2010
    Link to this post
    Much appreciated!

    One last question, the default forums control the author under last post displays the first and last name.
    When I tried to display the author, it displays the username, how would I retrieve the users first/last name?
    thePost.Owner.ToString();

  21. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    08 Jul 2010
    Link to this post
    Hi Kristian,

    Pass the username to ProfileBase class and then call GetPropertyValue method where you use FirstName as a parameter. The method will give you the first name of the user.

    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
  22. Kristian
    Kristian avatar
    214 posts
    Registered:
    03 Jun 2010
    08 Jul 2010
    Link to this post
    Thank you! That is exactly what I need, thanks for responding so quickly!

    -Kristian
  23. Roopesh
    Roopesh avatar
    39 posts
    Registered:
    29 Oct 2010
    15 Nov 2010
    Link to this post
    How to get all forum threads from a single forum . I have forum id

  24. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    15 Nov 2010
    Link to this post
    Hello Roopesh,

    You can take a look at the following article: Finding Forum Posts.

    Sincerely yours,
    Radoslav Georgiev
    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
  25. Daniel
    Daniel avatar
    1 posts
    Registered:
    29 Nov 2010
    03 Feb 2011
    Link to this post
    Hello,

    I was really excited to find this custom control as it matches my needs. Unfortunately, I can't make it work.

    I'm trying to run it on Sitefinity 3.7 SP4 (I think, not sure about the SP) Community Edition. After creating a ASCX file containing:

    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="SingleForumCustom.ascx.cs" Inherits="UserControls_SingleForumCustom" %>
     
    <asp:Literal ID="literal" runat="server" />

    Configuring it in web.config as:

    <add name="Single Forum View" section="Forums" url="~/UserControls/Forums/SingleForumCustom.ascx"
     description="Display a single forum" />

    And putting the code itself in a ASCX.CS file:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using Telerik.Forums.WebControls;
    using Telerik.Web.UI;
    using Telerik.Forums;
    using System.Collections;
    using Telerik.Framework.Web.Design;
      
    /// <summary>
    /// Summary description for SingleForumCustom
    /// </summary>
    ///
      
     [ControlDesignerAttribute("SingleForumControlDesigner, App_Code")]
    public partial class UserControls_SingleForumCustom : SingleForum
    {
        public string SingleForumCustom()
        {
        }
      
        protected override void CreateChildControls()
        {
            this.selectedForumID = SetSingleforumID;
            base.CreateChildControls();
        }
      
        public Guid SetSingleforumID
        {
            get
            {
                return this.id;
            }
            set
            {
                this.id = value;
            }
        }
        private Guid id;
    }
      
    public class UserControls_SingleForumControlDesigner : Telerik.Framework.Web.Design.ControlDesigner
    {
      
        public override string LayoutTemplatePath
        {
            get
            {
                return "~/CustomControls/SingleForumDesignerTempalate.ascx";
    ///            return "~/Sitefinity/ControlTemplates/Forums/SingleForum.ascx";
            }
      
        }
      
        protected override void InitializeControls(System.Web.UI.Control viewContainer)
        {
            base.InitializeControls(viewContainer);
        }
      
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
      
            if (Combo != null)
            {
                var manager = new ForumManager();
                IList allforums = manager.GetForums(true);
                RadComboBoxItem nullItem = new RadComboBoxItem("--SelecteItem--", string.Empty);
                Combo.Items.Add(nullItem);
                foreach (IForum forum in allforums)
                {
                    RadComboBoxItem item = new RadComboBoxItem(forum.Name, forum.ID.ToString());
                    Combo.Items.Add(item);
                }
      
                Combo.SelectedValue = ((SingleForumCustom)DesignedControl).SetSingleforumID.ToString();
            }
        }
        public override void OnSaving()
        {
            base.OnSaving();
            ((SingleForumCustom)DesignedControl).SetSingleforumID = new Guid(Combo.SelectedValue);
        }
      
      
        protected virtual RadComboBox Combo
        {
            get
            {
                return this.Container.GetControl<RadComboBox>("Combo1", true);
            }
        }
    }

    I'm getting the following error:

    ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).

    My experience with ASP is rather limited, so this could be something fairly simple to fix, but I can't find a way how.

    Thank you!
  26. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    03 Feb 2011
    Link to this post
    Hello,

    Please use a custom control - Class in App_Code or create a class library and put the logic there. Currently it looks like you are using a user control.

    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
26 posts, 0 answered