tags:

views:

60

answers:

3

So, I'm grabbing data from a sharepoint 2007 announcements list, and displaying it on another site. I need to make sure that the web part that I created is not displayed for people who don't have permissions for the site I'm getting the data from. How do I "disable" the web part if a user doesn't have permissions?

I've tried this.enabled = false in the onload() event, didn't work though.

A: 

I'm not certain what you mean by "disable" the Web Part. Your part can just not render any markup if the current user does not have rights to view the Announcements list.

Rob Windsor
I mean that I dont want the web part to even show up. currently, if they user does not have permissions it throws a permissions denied error, which I can't have showing up on the homepage of the sharepoint site, I need it to not show the web part at all, like audience targeting.
pinniger
Then you would set the Hidden property to true when the user does not have rights to view the Announcements list.
Rob Windsor
OK. The set the Hidden property on the Web Part to true when the current user does not have permissions to view the Announcements list.
Rob Windsor
A: 

To hide a web part altogether, set the web part's Hidden property to true. We follow this approach to hide a web part based on the existence/absence of some properties in a user's profile.

A hidden web part is still on the page, and takes part in the page lifecycle, but it's not visible to users. If you're still having problems with permissions errors, try catching the specific exception and using that as a test on whether or not to hide the part.

Certainly there's more elegant ways to checking permissions, but this approach should be quick and easy.

CBono
+1  A: 
protected override void Render(HtmlTextWriter output) {
    if (i have permissions) {
      base.Render(output);
    }
}

And to avoid UnauthorizedAccessException(s), be sure to check if user has appropriate permissions in any other place where you access any webs, lists and data.

Janis Veinbergs
Wont the title of the web part still be displayed on the page? and just no contents rendered?
pinniger