mardi 23 octobre 2012

Hide top navigation bar for Sharepoint 2010 / Cacher le ruban et la barre de navigation supérieur via code depuis la masterPage


Il ne faut pas oublier de passer les différents div en "runat='server'" pour que le code marche.

private void HideShowElement(bool value)
    {
        if(value) // Administrateur
    {    
    Control haut  = this.FindControl("msWwpselectlink");
//((HtmlControl)haut).Width="0px";
  ((HtmlControl)haut).Attributes.Add("style","display:block;");

Control hautLien  = this.FindControl("topNavgationBar");
  ((HtmlControl)hautLien).Attributes.Add("style","display:block;");


    Control crt = this.FindControl("PanelAdminLeft");
    if(crt!= null)
    {
    crt.Visible = true;
                //Supprime le css pour aligner à gauche.
                Control content = this.FindControl("MSO_ContentTable");
                if(content != null){
                ((HtmlControl)content).Attributes.Add("class","s4-ca s4-ca-dlgNoRibbon");}
    }
    }
    else  // Non administrateur
    {
    Control haut  = this.FindControl("msWwpselectlink");
// haut.Visible = false;
  ((HtmlControl)haut).Attributes.Add("style","display:none;");
  Control hautLien  = this.FindControl("topNavgationBar");
  ((HtmlControl)hautLien).Attributes.Add("style","display:none;");


    Control crt = this.FindControl("PanelAdminLeft");
    if(crt!= null)
    {
    crt.Visible = false;
                //Supprime le css pour aligner à gauche.
                Control content = this.FindControl("MSO_ContentTable");
                if(content != null){
                ((HtmlControl)content).Attributes.Remove("class");}
            }
    }
    }

Aucun commentaire :

Enregistrer un commentaire