Hiding a content block in v5.0

Posted by Community Admin on 04-Aug-2018 18:33

Hiding a content block in v5.0

All Replies

Posted by Community Admin on 24-Oct-2013 00:00

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?

Posted by Community Admin on 29-Oct-2013 00:00

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

This thread is closed