SharePoint 2013 – Audience trimmed web control

Hi everyone!

Recently I needed to come up with a way to conditionally show or hide a set of HTML markup (or ASP.NET markup – web parts / web controls, could be anything) on a master page. Decided to create a web control based on SharePoint audiences functionality. 

Principle is dead simple – in our markup we wrap the controls that we want hiding with our audience trimmed control, which, in turn, upon rendering will decide whether to render its inner markup (be it plain HTML, or another ASP.NET stuff) based on current users specific audience membership.

Here is the code of AudienceTrimmedContainer:

 

And, here is usage example
AudienceNames property accepts comma delimited names of your target audiences. If current user is in any of those – inner markup gets rendered!

Hope this will be of use to someone, till next time 🙂

 

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *