0

I need to hide quick launch in certain subsites in sp 2013. Below is the sample code (ascx.cs) i Tried, but quick launch is still visible. Not sure what is wrong with the code below.

 protected override void Render(HtmlTextWriter writer)
    {
        try
        {
            if (render != "0")
            {
          if (IsSubSite()) 
                    {
                        HideLeftNav();
     }
    }
   }

    private void HideStandardLeftNavForSite()
    {
        //ctl00_PlaceHolderLeftNavBar_QuickLaunchNavigationManager
        Control StandardLeftNavCtrl = FindControl(Page.Master.Controls, "QuickLaunchNavigationManager");
        if (StandardLeftNavCtrl != null)
            StandardLeftNavCtrl.Visible = false;
    }

    private void HideLeftNav()
    {
        Panel StandardLeftNavCtrl = (Panel)FindControl(Page.Master.Controls, "pnlQuickLaunch");
        if (StandardLeftNavCtrl != null)
            StandardLeftNavCtrl.Visible = false;           

    }

Thanks Venky

  • Will javascript and css help your case ? – Arvi Jul 25 '16 at 22:48
0

First create a css file and add below inside that

 <style type="text/css">  
      #sideNavBox {    
           display:none;  
      }  
 </style>  

Now your code behind will be

if (IsSubSite()) {
    HtmlLink styleLink = new HtmlLink();
    styleLink.Attributes.Add("rel", "stylesheet");
    styleLink.Attributes.Add("type", "text/css"); 
    styleLink.Href = "http://cssurl"; 
    this.Page.Header.Controls.Add(styleLink);
}
| improve this answer | |
  • I tried, but it is not working. 'protected override void CreateChildControls() { CssRegistration.Register("/_layouts/15/1033/styles/hidequicklaunch.css"); }' – user2459457 Jul 26 '16 at 15:26
  • Can you view page source and check the style is getting registered.. Also debug and make sure it goes inside the if condition – Amal Hashim Jul 26 '16 at 15:27
  • I can see that in view source and link is fine. It works, if i put that same block of css in an existing static css file referenced in master page. So the style works, But not through code. Does it has to be registered prerender or page init? – user2459457 Jul 26 '16 at 15:29
  • Try moving the code in Pre Render events – Amal Hashim Jul 26 '16 at 15:33
  • View source: <link rel="stylesheet" type="text/css" href="/_layouts/15/1033/styles/hidequicklaunch.css"/> <div class="left-navContainer ms-dialogHidden"> <div id="sideNavBox" class="ms-dialogHidden ms-forceWrap ms-noList"> <div id="DeltaPlaceHolderLeftNavBar" class="ms-core-navigation" role="navigation"> <div class="ms-core-sideNavBox-removeLeftMargin"> ** <div id= "quickLaunch">** <div id="ctl00_PlaceHolderLeftNavBar_QuickLaunchNavigationManager" class="ms-Dialoghidden"> – user2459457 Jul 26 '16 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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