How to hide the ribbon in a custom SharePoint page having a Visual Web part shown as pop up / Modal dialog in SharePoint 2013

Ashok Raja
 
Solutions Architect
July 30, 2013
 
Rate this article
 
Views
831

Call the below mentioned function in Page Load function of the Web part to hide the ribbon row of the page if shown in pop up. This piece of code injects a css into the page to hide the ribbon row based on the way the page is displayed to the user. A query string  called IsDlg=1 is automatically added  by SharePoint if the page is displayed as pop up. This code checks for the availability of that query string and conditionally injects the code to the page.

Code to hide Ribbon Row

 private void HideRibbonOnDialog(Control clt)
 {
     if (clt.Page.Request.QueryString["IsDlg"] == "1")
     {
         LiteralControl lt = new LiteralControl(@"<style type='text/css'> #s4-ribbonrow{display:none !important;} </style>");
         lt.EnableViewState = false;
         clt.Controls.Add(lt);
     }
 }

Calling the code in Page Load of web part

  protected void Page_Load(object sender, EventArgs e)
 {
     HideRibbonOnDialog(this);
 }
Note : If you add IsDlg=1 specifically to the URL while showing it as Modal dialog, you will end up with  duplicate IsDlg key. This in turn ,  the value returned for IsDlg would be “1,1” and not 1 . If you are not sure about duplicate usage of IsDlg , then just check for the availability of  IsDlg as a query string parameter rather that checking its value.
Category : Tips

Author Info

Ashok Raja
 
Solutions Architect
 
Rate this article
 
I am Ashok Raja, Share Point Consultant and Architect based out of Chennai, India. ...read more
 

Leave a comment