1

I have designed the quick launch for a SharePoint 2010 site in master page, Now for some pages I do not want the quick launch to show up, (Or better say some SharePoint groups).

So I added a web part with the following code to hide the Quick launch for that pages,

<style>
#s4-leftpanel{
display:none
}
.s4-ca{
margin-left:0px
}
</style>

Now the problem is , if the page loads too slow the master page will show the quick Launch, till the web part executes, and the users can see or even click the links in the quick launch, that they are not supposed to see..

How can I get rid of this problem?

4 Answers 4

2

You dont have to use code behind if you could use SPServices Jquery from CodePlex.

Do the necessary steps:

  1. Download the jquery.SPServices-0.6.2.js from SPServices Jquery.

  2. Upload the minnified js file - 'jquery.SPServices-0.6.2.min.js' to the style library of your site.

  3. Add the script link <script type="text/javascript" src="Path of the JS file"> </script> to the master page.

  4. Add the following code

    var groupName; $().SPServices({ operation: "GetGroupCollectionFromUser", userLoginName: $().SPServices.SPGetCurrentUser(), async: false, completefunc: function(xData, Status) { alert(xData.responseXML.xml); $(xData.responseXML).find("[nodeName=Group]").each(function() {
    groupName = $(this).attr("Name"); }); } });

  5. Now, you have the group name in the variable groupName. Put an 'If' condition to check whether it matches your logic and then add the code to disable the quick launch.

This also should eliminate your need of even adding web part on each pages as this piece of code sits in the master page.

10
  • Thank you for this detail info +1. How ever I guess I should go for Daniel's method, since we can do it with out any J script.
    – Jithu
    Commented Dec 5, 2011 at 8:12
  • Hi Deepu how can I write the code, QuickLaunchNavigationManager.Visible = false; inside the if condition, I am trying to hide it !!
    – Jithu
    Commented Dec 6, 2011 at 5:28
  • var groupName; $().SPServices({ operation: "GetGroupCollectionFromUser", userLoginName: $().SPServices.SPGetCurrentUser(), async: false, completefunc: function(xData, Status) { alert(xData.responseXML.xml); $(xData.responseXML).find("[nodeName=Group]").each(function() { groupName = $(this).attr("Name"); }); } }); if($.trim(groupName) != 'Ms Presales') { QuickLaunchNavigationManager.Visible = false; } This is the one I wrote, Doesn't Seem to be working !!
    – Jithu
    Commented Dec 6, 2011 at 5:40
  • Paste this code after the PlaceHolderMain contentplaceholder var groupName; $().SPServices({ operation: "GetGroupCollectionFromUser", userLoginName: $().SPServices.SPGetCurrentUser(), async: false, completefunc: function(xData, Status) { $(xData.responseXML).find("[nodeName=Group]").each(function() {groupName = $(this).attr("Name");}); } }); if($.trim(groupName) != 'Ms Presales') {document.getElementById('s4-leftpanel').style.display = 'none'; } Please make sure the groupname is correct. :)
    – Deepu Nair
    Commented Dec 6, 2011 at 6:33
  • Getting an error Message: 'jQuery' is undefined Line: 20 Char: 1 Code: 0 URI: sok:1234/Scripts/jquery.SPServices-0.7.0.js
    – Jithu
    Commented Dec 6, 2011 at 7:37
2

Use codebehind in the master page to check if the current user is a member of the group (or not), then use the Visible property on the Quick Launch web control to hide it.

Control:

<Sharepoint:SPNavigationManager
            id="QuickLaunchNavigationManager"
            runat="server" ...

Code behind (eg on Page_Load)

QuickLaunchNavigationManager.Visible = false;
2
  • Hi Dan, One quick doubt, I was editing the master page in Share Designer 2010, then how can I add a code behind to this master page ?
    – Jithu
    Commented Dec 6, 2011 at 4:43
  • You will need to build the code behind in Visual Studio, create a class which inherits from MasterPage, then inherit from your class in the masterpage file. Deploy the .dll using a WSP. You can still edit the masterpage in SharePoint Designer, but it is attached to the codebehind as it now inherits your class, instead of the default. Commented Dec 6, 2011 at 6:26
1

not necessary to modify your Master page code behind, you can use DelegateControl: http://www.sharepointnutsandbolts.com/2007/06/using-delegate-control.html

1
  • Thanks Ivan, Let me check it as I am not too good with Delegate Control!!
    – Jithu
    Commented Dec 6, 2011 at 4:42
1

other way to do it is to wrap QuickLaunch layout in your master in SecurityTrimmedControl

Your Answer

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

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