Skip to main content

Posts

Showing posts from January, 2014

Dynamically add UserControls/WebPart based on User Role

I am building a "dashboard" and want to dynamically load different catalogs based on user roles. I searched quite lot to figure out how to dynamically / programmatically add a DeclarativeCatalogPart to a CatalogZone. But couldn't find out perfect solution. The issues I faced are listed below. 1. The CatalogZone control can only contain CatalogPart controls, so you can't dynamically load controls into this section. 2. Tried to use WebPartsListUserControlPath property, by loading usercontrols programatically based on user role. Eventhough it doesn't throw any error, controls are not properly rendered in run time. I tried some other things too (except building a "Custom CatalogPart"), but none worked. So I dropped the idea of avoiding hard-coded catalog and solved the issue in the below manner. In this case authorization is not completely database driven, still... The below approach allows you to set permissions to Web Parts based on user roles