Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a project with a number of custom ribbons: a couple are bound to contenttypes, some are activated through webparts and some are (sub)site-wide and are supposed to be activated by a delegate control.

All the ribbons are in a site-scoped feature, and the delegate control is in a web-scoped feature, because these ribbons are supposed to show only on the subsites.

However, something does not work. I think it's not the ribbon-xml because if I bind it to a contenttype the ribbon shows up as expected. If I attach to the IIS Worker process and reload the page, the breakpoint in the OnPreRender of the delegate control is not reached. So my best guess is that something is wrong with the delegate control. What that is I don't know.

ShowAdminMenuControl.cs:

namespace MyProject.Ribbons.ShowAdminMenu
{
    class ShowAdminMenuControl : WebControl
    {
        private bool isLeverancierSite;
        private bool isRegisteredUser;
        private string typeGebruiker;
        private int? gebruikerId;

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            SPWeb web = SPContext.Current.Web;

            isLeverancierSite = Functions.GetWebProperty(web, WebProperties.SiteType) == SiteTypes.Leverancier;
            isRegisteredUser = Functions.GetCurrentGebruiker(web, out typeGebruiker, out gebruikerId);

            #region show ribbon
            if (!isRegisteredUser || typeGebruiker == Gebruiker.Admin)
            {
                SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
                if (ribbon != null)
                {
                    ribbon.Minimized = false;
                    ribbon.CommandUIVisible = true;
                    string adminMenuTabId = String.Format("MyProject.Ribbon.{0}.AdminMenu.Tab", (isLeverancierSite ? "Leverancier" : "Intermediair"));
                    if (!ribbon.IsTabAvailable(adminMenuTabId))
                    {
                        ribbon.MakeTabAvailable(adminMenuTabId);
                    }
                    ribbon.InitialTabId = adminMenuTabId;
                }
            }
            #endregion
        }
    }
}

Elements.xml of ShowAdminMenu

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
   <Control Id="AdditionalPageHead"
         Sequence="99"
         ControlAssembly="$SharePoint.Project.AssemblyFullName$"
         ControlClass="MyProject.Ribbons.ShowAdminMenu.ShowAdminMenuControl"/>
</Elements>

Elements.xml of AdminMenu:

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction Id="MyProject.Ribbon.Leverancier.AdminMenu"
                Location="CommandUI.Ribbon"
                Title="Adminmenu Leveranciersite">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition Location="Ribbon.Tabs._children">
          <Tab Id="MyProject.Ribbon.Leverancier.AdminMenu.Tab"
               Title="Beheer"
               Description="Beheerpagina's voor Admins"
               Sequence="21">
            <Scaling Id="MyProject.Ribbon.Leverancier.AdminMenu.Scaling">
              <MaxSize Id="MyProject.Ribbon.Leverancier.AdminMenu.Scaling.MaxSize"
                       GroupId="MyProject.Ribbon.Leverancier.AdminMenu.Group"
                       Sequence="1"
                       Size="Large"/>
              <Scale Id="MyProject.Ribbon.Leverancier.AdminMenu.Scaling.Scale"
                     GroupId="MyProject.Ribbon.Leverancier.AdminMenu.Group"
                     Sequence="2"
                     Size="Large"/>
            </Scaling>
            <Groups Id="MyProject.Ribbon.Leverancier.AdminMenu.Groups">
              <Group Id="MyProject.Ribbon.Leverancier.AdminMenu.Group"
                     Description="Lijsten"
                     Title="Lijsten"
                     Sequence="11"
                     Template="MyProject.Ribbon.Leverancier.AdminMenu.Template">
                <Controls Id="MyProject.Ribbon.Leverancier.AdminMenu.Controls">
                  <Button Id="MyProject.Ribbon.Leverancier.AdminMenu.Gebruikers"
                          Command="MyProject.Commands.Leverancier.AdminMenu.Gebruikers"
                          Sequence="11"
                          Description="Beheer gebruikers"
                          Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-144" Image16by16Left="0"
                          Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-128" Image32by32Left="-256"
                          LabelText="Gebruikers"
                          TemplateAlias="o1"/>
                  <Button Id="MyProject.Ribbon.Leverancier.AdminMenu.Statussen"
                          Command="MyProject.Commands.Leverancier.AdminMenu.Statussen"
                          Sequence="12"
                          Description="Beheer statussen"
                          Image16by16="/_layouts/$Resources:core,Language;/images/formatmap16x16.png" Image16by16Top="-144" Image16by16Left="0"
                          Image32by32="/_layouts/$Resources:core,Language;/images/formatmap32x32.png" Image32by32Top="-128" Image32by32Left="-256"
                          LabelText="Statussen"
                          TemplateAlias="o1"/>
                </Controls>
              </Group>
            </Groups>
          </Tab>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="MyProject.Ribbon.Leverancier.AdminMenu.Template">
            <Layout Title="Large">
              <OverflowSection Type="OneRow" TemplateAlias="o1" DisplayMode="Large" />
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler Command="MyProject.Commands.Leverancier.AdminMenu.Gebruikers"
                          CommandAction="javascript:window.location='{SiteUrl}/Lists/Gebruikers';"/>
        <CommandUIHandler Command="MyProject.Commands.Leverancier.AdminMenu.Statussen"
                          CommandAction="javascript:window.location='{SiteUrl}/Lists/Statussen';"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
  <CustomAction Id="MyProject.Ribbon.Script"
                Location="ScriptLink"
                ScriptSrc="/_layouts/MyProject/Ribbons/MyProject.ribbon.js" />
</Elements>
share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

Have you added a SafeControl for your WebControl?

(If you check the ULS it should say that in plain English :-)

share|improve this answer
    
That did the trick! I thought it would something relatively simple. Thanks a lot! –  Janne Louw Jun 17 '11 at 10:51
add comment

I see that you set 99 for the sequence.

do you know that it's the control with the lowest sequence number is added to the tree ?

share|improve this answer
2  
This is true, but not always. In this situation, OOTB AdditionalPageHead delegate has AllowMultipleControls property set to true, so you can place any number of controls into this delegate. Check the reference: msdn.microsoft.com/en-us/library/… –  Andrey Markeev Jun 15 '11 at 10:18
    
Good Point omlin! –  GillouX Jun 15 '11 at 12:41
add comment

Is this code for SharePoint 2010? I try use simillar code and it doesn't work in SharePoint 2010. What may the reason?

My code example: Elements.xml of RibbonTab:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="MyCustomRibbonTab"
    Location="CommandUI.Ribbon"
    >
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Tabs._children">
          <Tab
            Id="Ribbon.CustomTabExample"
            Title="Рейтинг"
            Description="Управление рейтингом страницы!"
            Sequence="501">
            <Scaling
              Id="Ribbon.CustomTabExample.Scaling">
              <MaxSize
                Id="Ribbon.CustomTabExample.MaxSize"
                GroupId="Ribbon.CustomTabExample.CustomGroupExample"
                Size="TwoMedium"/>
              <Scale
                Id="Ribbon.CustomTabExample.Scaling.CustomTabScaling"
                GroupId="Ribbon.CustomTabExample.CustomGroupExample"
                Size="TwoMedium" />
            </Scaling>
            <Groups Id="Ribbon.CustomTabExample.Groups">
              <Group
                Id="Ribbon.CustomTabExample.CustomGroupExample"
                Description="Установка рейтинга страницы!"
                Title="Рейтинг"
                Sequence="52"
                Template="Ribbon.Templates.CustomTemplateExample">
                <Controls Id="Ribbon.CustomTabExample.CustomGroupExample.Controls">
                  <Button
                    Id="Ribbon.CustomTabExample.CustomGroupExample.GoodbyeWorld"
                    Command="CustomTabExample.GoodbyeWorldCommand"
                    Sequence="17"
                    Description="Задать рейтинг"
                    LabelText="Задать рейтинг"
                    TemplateAlias="cust2"/>
                  <Button
                    Id="Ribbon.CustomTabExample.CustomGroupExample.LoveWorld"
                    Command="CustomTabExample.LoveWorldCommand"
                    Sequence="19"
                    Description="Задать административный рейтинг"
                    LabelText="Задать административный рейтинг"
                    TemplateAlias="cust3"/>
                </Controls>
              </Group>
            </Groups>
          </Tab>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.CustomTemplateExample">
            <Layout
              Title="TwoMedium"
              LayoutTitle="TwoMedium">
              <Section Alignment="Top" Type="TwoRow">
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust2" />
                </Row>
                <Row>
                  <ControlRef DisplayMode="Medium" TemplateAlias="cust3" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="CustomTabExample.GoodbyeWorldCommand"
          CommandAction="javascript:alert('Good-bye, world!');" />
        <CommandUIHandler
          Command="CustomTabExample.LoveWorldCommand"
          CommandAction="javascript:alert('I love you, world!');" />
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

ShowRibbonControl.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Web.CommandUI;


namespace ShowRibbon
{
    class ShowRibbonControl : WebControl
    {
        protected override void OnPreRender(EventArgs e)
        {

            base.OnPreRender(e);
            SPWeb web = SPContext.Current.Web;
            #region show ribbon

            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            if (ribbon != null)
            {
                ribbon.Minimized = false;
                ribbon.CommandUIVisible = true;
                string adminMenuTabId = "MyCustomRibbonTab";
                if (!ribbon.IsTabAvailable(adminMenuTabId))
                {
                    ribbon.MakeTabAvailable(adminMenuTabId);
                }
                ribbon.InitialTabId = adminMenuTabId;
            }

            #endregion
        }
    }

}

And Elements.xml of ShowRibbon:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Control Id="AdditionalPageHead"
        Sequence="99"
        ControlAssembly="$SharePoint.Project.AssemblyFullName$"
        ControlClass="ShowRibbon.ShowRibbonControl"/>
</Elements>

I add a SafeControl for element ShowRibbon. And when I set breakpoiont in OnPreRender and refresh page, there is not reached.

share|improve this answer
    
Yes, the ribbon is only in SharePoint 2010. Since this isn't really an answer, you might want to try asking a new question. Please ask it by clicking the Ask Question button. –  Kit Menke Jan 19 '12 at 16:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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