I work in a financial company where we have Resident Engineers and they have account in Active Directory but they dont have official email addresses.

My portal acrhitecture is like everyonce can visit portal and on my Home.aspx I have a Content Editor Webpart in which I have a link called "Purchase Requisition" which is valid for the users who has email addresses of the company.

When user opens the new requisition custom form (A Visual Webpart) actually it checks the user name and then try to locate the email addresses in my Hiererchy list and if found it retrieves the user information and display and it opens this requisition form in Modal Dialog.

What I want is if those users who has no company email addresses opens the portal then the CEWP which contains Requisition link should be hidden.

i got this code from somewhere how and where should I use it in this condition? or is there any javascript way to query list and seek value and based on that value hide and unhide webpart?

PWeb myWeb = SPContext.Current.Web;
myWeb.AllowUnsafeUpdates = true;

Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
mgr = myWeb.GetLimitedWebPartManager(
foreach (System.Web.UI.WebControls.WebParts.WebPart myWebPart in mgr.WebParts)
    // If this is the webpart we want to change...
    if (myWebPart.Title == "SomeWebpartName")
        myWebPart.Hidden = true;

2 Answers 2


First of all: imho I wouldn't use the code sample you have included in your question. That would only allow you to cycle on the collection of web parts available on a page, and then hide the target webpart based on the name. Unless you add some other logic it won't help you, and even then it seems a "cannon to hunt a rabbit" approach (you would modify the page on each run only to perform a security trimming process).

Three alternatives come to mind:

a) change the content editor wp to a custom wp. It shouldn't be hard and you could always use the wp to provide aditional info based on the context (a link to require a mail to be added? some it staff contact info?).

b) keep the content editor wp and use a script to dinamically hide the link. You could follow two approach: create an server side control which is included as a delegate control and register the script in codebehind (so that you can check the mail in server side code) or use the ecma script infrastructure to build that check client side.

c) build a claim sistem and use a claim to recognize users that have a mail. You could then try and define an audit filter on the content editor wp. Notice that claims may require too much effort for the value, so consider them only if you feel that they would be usefull in other situations too.


You can use CSOM or SPServices to get the information about the current logged in user and based on that then you can use simple javascript function to hide/unhide the webpart And all this can be done in the CEWP. To hide a webaprt find its ID and set display to none.

<script type="text/javascript"> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.