gpt4 book ai didi

sharepoint - SharePoint 中的多个 Web 部件和功能区

转载 作者:行者123 更新时间:2023-12-03 09:46:39 25 4
gpt4 key购买 nike

我正在将功能区关联到我的 Web 部件。我需要在一个页面中添加两个以上的 Web 部件。

我不想为每个 Web 部件设置单独的上下文组/选项卡。有没有办法检查页面当前功能区中是否存在特定组/选项卡?

此时,当我向页面添加多个 webpart 时,出现以下错误:

项目已经被添加。字典中的键:'Ribbon.MyContextualTabGroup' 正在添加的键:'Ribbon.MyContextualTabGroup'

这是我的代码供您引用:

/// <summary>
/// Gets the web part contextual info.
/// </summary>
public WebPartContextualInfo WebPartContextualInfo
{
get
{
var webPartContextualInfo = new WebPartContextualInfo();
var webPartRibbonContextualGroup = new WebPartRibbonContextualGroup();
var webPartRibbonTab = new WebPartRibbonTab();

webPartRibbonContextualGroup.Id = "Ribbon.MyContextualTabGroup";
webPartRibbonContextualGroup.Command = "MyContextualTab.EnableContextualGroup";
webPartRibbonContextualGroup.VisibilityContext = "MyContextualTab.CustomVisibilityContext";

webPartRibbonTab.Id = "Ribbon.MyTab";
webPartRibbonTab.VisibilityContext = "MyContextualTab.CustomVisibilityContext";

webPartContextualInfo.ContextualGroups.Add(webPartRibbonContextualGroup);
webPartContextualInfo.Tabs.Add(webPartRibbonTab);
webPartContextualInfo.PageComponentId = SPRibbon.GetWebPartPageComponentId(this);

return webPartContextualInfo;
}
}

/// <summary>
/// Adds the contextual tab.
/// </summary>
private void AddContextualTab()
{
SPRibbon spRibbon = SPRibbon.GetCurrent(Page);

if (spRibbon == null) return;

var ribbonExtensions = new XmlDocument();

ribbonExtensions.LoadXml(_contextualTab);
spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.ContextualTabs._children");

ribbonExtensions.LoadXml(_contextualTabTemplate);
spRibbon.RegisterDataExtension(ribbonExtensions.FirstChild, "Ribbon.Templates._children");
}

/// <summary>
/// The event handler for the System.Web.UI.Control.PreRender event that occurs immediately before the Web Part is rendered to the Web Part Page it is contained on.
/// </summary>
/// <param name="e">A System.EventArgs that contains the event data.</param>
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);

AddContextualTab();

ClientScriptManager clientScriptManager = Page.ClientScript;
clientScriptManager.RegisterClientScriptBlock(GetType(), "MyWebPart", DelayScript);
}

最佳答案

不能在 Web 部件的不同实例之间共享上下文功能区。因为仅当您的 Web 部件实例在页面上具有“焦点”时才会显示功能区。因此,Web 部件的多个实例必须创建它们自己的上下文组。

为避免功能区 ID 重复,将 Web 部件实例特定部件附加到功能区 ID。您可以使用 Web 部件的 ID:

webPartRibbonContextualGroup.Id = "Ribbon.MyContextualTabGroup." + ID;
// ...
webPartRibbonTab.Id = "Ribbon.MyTab." + ID;
// etc.

关于sharepoint - SharePoint 中的多个 Web 部件和功能区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6379938/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com