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

Forums / Developing with Sitefinity / Forum Sample Code

Forum Sample Code

4 posts, 0 answered
  1. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    09 Jan 2010
    Link to this post
    Does anybody have some sample code to built a forum on a current site. I created a forum within the Admin console and added a control to my page, I  want to setup so users can see list of forums (I got this) then I want them to click on a forum and see the threads ( I got this). I then want them to click on a thread to read and reply to it. Using basic control it gives the option of editing (which I do not want) and it does not display all the replies in a list which I want basically something like you have here EXCEPT I want have it open for anonymous users.
  2. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    10 Jan 2010
    Link to this post
    OK I got everything working, but does anybody have the code to hide the edit and delete buttons and to keep people from editing post?
  3. Steven Lancaster
    Steven Lancaster avatar
    82 posts
    Registered:
    06 Nov 2009
    10 Jan 2010
    Link to this post
    OK got everything setup just right except I need to moderate new threads.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Jan 2010
    Link to this post
    Hi Steven Lancaster,

    You can add logic to Sitefinity/ControlTemplates/SingleForum.ascx to hide the buttons. You can create a code behind of the templates or write your logic inline.

    protected override void OnPreRender(EventArgs e)
      {
          // hide the buttons for all users that do not belong to administrators
          //group
          base.OnPreRender(e);
          if (!UserManager.IsCurrentUserInRole("administrators"))
          {
              this.newThreadButton1.Visible = false;
              this.newThreadButton2.Visible = false;
          }
     
      }

    Sitefinity/ControlTemplates/SingleThread.ascx

    protected override void OnPreRender(EventArgs e)
       {
           base.OnPreRender(e);
           IButtonControl editButton = FindControlRecursive(allPosts, "btnEdit") as IButtonControl;
           IButtonControl deleteButton = FindControlRecursive(allPosts, "btnDelete") as IButtonControl;
           (editButton as WebControl).Visible = false;
           (deleteButton as WebControl).Visible = false;
     
       }
     
       private Control FindControlRecursive(Control root, string id)
       {
           if (root.ID == id)
           {
               return root;
           }
     
           foreach (Control c in root.Controls)
           {
               Control t = FindControlRecursive(c, id);
               if (t != null)
               {
                   return t;
               }
           }
     
           return null;
       }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered