It's a real drag and performance killer to have to load all the WebParts on a page and then laboriously hide and reveal all the ones relevant to user groups / permission levels. Especially when on the homepage (being the best place to show users their important stuff...) - it grinds the site/farm as well as causing major debug overhead. Surely there's a better way of targetting users with only their relevant webparts and not even having to load and hide irrelevant webparts?
So instead of using the old:
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
mgr = oWebUserTokened.GetLimitedWebPartManager(url, system.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
// first hide them all to avoid exposure…
foreach (System.Web.UI.WebControls.WebParts.WebPart thisWebPart1 in mgr.WebParts)
{
thisWebPart1.Hidden = true;
mgr.SaveChanges(thisWebPart1);
}
// and then reveal the required ones….
foreach (System.Web.UI.WebControls.WebParts.WebPart thisWebPart2 in mgr.WebParts)
{
if (boolThisTypeOfUser) // needs particular webparts
{
if (thisWebPart2.Title == "Special Webpart Title")
SetWebPartVisibility(mgr, thisWebPart2); // Show the WebPart etc
}
else // check for other user types…
}
... and revealing the ones appropriate to the user, is there a way of bypassing to avoid loading irrelevant webparts at all?
I appreciate you may shout "use Audiences!!" but A) am on Foundation, and B) not sure if they load everything but then hide anyway, ie same overhead.
Seeing as we're in CreateChildControls() anyway, you'd have thought it was simple to merely avoid loading the irrelevant webparts, but either it's not, or I'm missing something obvious!
