自定义选项卡上的自定义按钮始终处于禁用状态(功能区)

4

我找到了很多有关如何在功能区上添加自定义选项卡和自定义控件的示例,但是没有一个适用于我。我获得了自定义选项卡,但按钮总是被禁用。

这是我当前的代码版本:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Id="CustomRibbonTab"
    Location="CommandUI.Ribbon"
    RegistrationId="101"
    RegistrationType="List">
    <CommandUIExtension>
      <CommandUIDefinitions>
        <CommandUIDefinition
          Location="Ribbon.Tabs._children">
          <Tab
            Id="Ribbon.CustomTab"
            Title="Custom Tab"
            Description="Custom Tab !!!"
            Sequence="701">
            <Scaling
              Id="Ribbon.CustomTab.Scaling">
              <MaxSize
                Id="Ribbon.CustomTab.MaxSize"
                GroupId="Ribbon.CustomTab.CustomGroup"
                Size="OneLargeTwoMedium"/>
              <Scale
                Id="Ribbon.CustomTab.Scaling.CustomTabScaling"
                GroupId="Ribbon.CustomTab.CustomGroup"
                Size="OneLargeTwoMedium" />
            </Scaling>
            <Groups Id="Ribbon.CustomTab.Groups">
              <Group
                Id="Ribbon.CustomTab.CustomGroup"
                Description="Custom Group!"
                Title="Custom Group"
                Sequence="62"
                Template="Ribbon.Templates.CustomTemplate">
                <Controls Id="Ribbon.CustomTab.CustomGroup.Controls">
                  <Button
                    Id="Ribbon.CustomTab.CustomGroup.CustomButton"
                    Command="CustomTab.CustomButtonCommand"
                    Sequence="115"
                    Description=""
                    LabelText="Custom Button"
                    Image32by32="/_layouts/images/PPEOPLE.GIF"
                    TemplateAlias="cust1"/>
                </Controls>
              </Group>
            </Groups>
          </Tab>
        </CommandUIDefinition>
        <CommandUIDefinition Location="Ribbon.Templates._children">
          <GroupTemplate Id="Ribbon.Templates.CustomTemplate">
            <Layout
              Title="OneLargeTwoMedium"
              LayoutTitle="OneLargeTwoMedium">
              <Section Alignment="Top" Type="OneRow">
                <Row>
                  <ControlRef DisplayMode="Large" TemplateAlias="cust1" />
                </Row>
              </Section>
            </Layout>
          </GroupTemplate>
        </CommandUIDefinition>
      </CommandUIDefinitions>
      <CommandUIHandlers>
        <CommandUIHandler
          Command="CustomTab.CustomButtonCommand"
           CommandAction="javascript:alert('Hello, world!');"
          EnabledScript="javascript:return true;"/>
      </CommandUIHandlers>
    </CommandUIExtension>
  </CustomAction>
</Elements>

我清理了缓存。我阅读了关于CommandUIHandler中EnabledScripts属性的重要性的文章。但我始终得到相同的结果:Disabled button。有人遇到过同样的问题吗?请帮忙!

我在SP2013中遇到了同样的问题。你能解决它吗? - vk_muse
@vk_muse,请尝试清除缓存并进行硬重载。就我记得而言,它对我有所帮助。 - Oleg Kyrylchuk
2个回答

3
我检查了一个本地的自定义操作,其中EnabledScript遵循了不同的模式:
EnabledScript="javascript:function JustReturnTrue()
{
      return true
}
JustReturnTrue();" 

如果您的项目显示出来,但始终处于禁用状态,我敢打赌问题就在这里。

我认为该属性无论如何都是可选的,如果我没记错的话。


谢谢您的回复,但是它并没有帮助到我。 - Oleg Kyrylchuk

3

我曾经遇到过同样的问题,不确定这是否是正确的解决方案,因为我是新手。我从作用域设置为“网站”的功能中删除了该元素,添加了另一个功能,并将作用域设置为“Web”。在此功能中添加了我的按钮项,保存、部署并启用了来自网站功能的新功能,然后它就起作用了。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接