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

Forums / Developing with Sitefinity / Hiding a content block in v5.0

Hiding a content block in v5.0

2 posts, 0 answered
  1. Jeff
    Jeff avatar
    5 posts
    Registered:
    10 Apr 2013
    24 Oct 2013
    Link to this post
    I created a new class that inherits from Telerik.Sitefinity.Modules.GenericContent.Web.UI.ContentBlock. The purpose of this class is to be able to administer on the page editor whether a content block can be should be visible to anonymous users or authenticated users.

    public class AuthorizedContentBlock : ContentBlock
    {
        public bool HideFromAnonymousUser { get; set; }
        public bool HideFromAuthenticatedUser { get; set; }
     
        protected override void Render(HtmlTextWriter writer)
        {
            var authenticated = ... //custom implementation
            if (HideFromAnonymousUser && !authenticated)
            {
                this.Visible = false;
            }
     
            if(HideFromAuthenticatedUser && authenticated)
            {
                this.Visible = false;
            }
     
            base.Render(writer);
        }
    }

    I added the control to the toolbox, dragged it on the page and added content with no problem. The problem is that when I navigate to the page with the block, none of my code was run! I ran in debug mode with breakpoints and none were hit. However, the breakpoints ARE hit when I am viewing the page in the Sitefinity editor (/Action/Edit). 

    The page is using global cache settings and the global setting for the Output Cache is disabled (though the Client Cache is enabled). 

    How can I programmatically hide a content block? Is there a better way for me to be doing this?
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    30 Nov 2016
    29 Oct 2013
    Link to this post
    Hello,

    Inject the logic in InitializeControls method override InitializeControls and after calling the base method add the logic for hiding the control.
    protected override void InitializeControls(GenericContainer container)
    InitializeControls is the sitefinity equivalent for CreateChildControls .


    Regards,
    Stanislav Velikov
    Telerik
    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
2 posts, 0 answered