SharePoint 在页面上显示带有多个 Web 部件的功能区

发布于 2024-12-13 20:06:26 字数 821 浏览 5 评论 0原文

我创建了一个共享点页面,其中包含一个 xslt Web 部件和一个与问题无关的第二个 Web 部件,

当我们添加第二个 Web 部件时,功能区栏被隐藏,您必须单击该 Web 部件才能再次显示功能区栏。 我们无法要求用户单击 Web 部件,因此我尝试在 xslt 列表视图 Web 部件的上下文中使功能区栏始终可见。

在搜索此问题时,我发现当您在 SharePoint 源代码中使用反射器搜索此隐藏功能区行为时,这似乎是 Microsoft 设计的行为,如下例所示:

public override bool Visible { 
get {
if (!this.SingleWebPartPresentOnPage)
return false;
else
return base.Visible; 
} 
}

有人遇到相同问题但没有解决方案:http://www.glynblogs.com/2011/02/list-view-selector-missing-with-multiple-web-parts-in-sharepoint-2010.html

可能吗强制功能区栏通过服务器端代码可见,或者我可以调用当我单击 Web 部件以显示功能区栏时正在使用的 javascript 代码吗?

我认为使用 javascript 应该可以,因为如果您单击 xslt web 部件,功能区是可见的,但我无法重现正在执行的代码。

I've created a sharepoint page that has an xslt webpart and a 2nd webpart that is unrelated to the question

When we add this second webpart the ribbon bar is hidden and you have to click the webpart to get the ribbon bar shown again.
Clicking the webpart isn’t something we can ask from our users so I’m trying to get the ribbon bar visible at all times with the context of our xslt listview webpart.

When searching for this problem I found out that when you search for this hidden ribbon behavior with reflector in the SharePoint source code it seems this is behavior that is designed by Microsoft as the example below shows:

public override bool Visible { 
get {
if (!this.SingleWebPartPresentOnPage)
return false;
else
return base.Visible; 
} 
}

Someone with same problem but no solution: http://www.glynblogs.com/2011/02/list-view-selector-missing-with-multiple-web-parts-in-sharepoint-2010.html

Is it possible to force the ribbon bar to visible with server side code or can I call the javascript code that is being used when I click the webpart to show the ribbon bar?

I think it should be possible with javascript because if you click the xslt webpart the ribbon is visible but i can't reproduce the code thats being executed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

人│生佛魔见 2024-12-20 20:06:26

您可以使用 JavaScript 重新选择 XSLTListViewWebPart,功能区将再次出现。

$(document).ready(function() { 
    var target = document.getElementById("MSOZoneCell_WebPartWPQ2"); 
    if(target != null) { 
        var fakeEvent = new Array();
        fakeEvent["target"] = target;
        fakeEvent["srcElement"] = target;
        WpClick(fakeEvent); 
    } 
 });

you can use JavaScript to reselect the XSLTListViewWebPart, that the ribbon appears again.

$(document).ready(function() { 
    var target = document.getElementById("MSOZoneCell_WebPartWPQ2"); 
    if(target != null) { 
        var fakeEvent = new Array();
        fakeEvent["target"] = target;
        fakeEvent["srcElement"] = target;
        WpClick(fakeEvent); 
    } 
 });
不语却知心 2024-12-20 20:06:26

下面的Javascript对我有用!

<script>
setTimeout(function() {
var elem = document.getElementById("MSOZoneCell_WebPartWPQ4");
if(elem != null) {
var dummyevent = new Array();
dummyevent["target"] = elem;
dummyevent["srcElement"] = elem;
WpClick(dummyevent);
}
}, 100);
</script>

在上面的脚本中,MSOZoneCell_WebPartWPQ4 是我的列表视图 Web 部件

Below Javascript worked for me!!

<script>
setTimeout(function() {
var elem = document.getElementById("MSOZoneCell_WebPartWPQ4");
if(elem != null) {
var dummyevent = new Array();
dummyevent["target"] = elem;
dummyevent["srcElement"] = elem;
WpClick(dummyevent);
}
}, 100);
</script>

In the above script the MSOZoneCell_WebPartWPQ4 being my list view web part

放肆 2024-12-20 20:06:26

一个很好的解决方案是获取视图页面上主 Web 部件的 contextualInfo。

public class MyView : WebPart, IWebPartPageComponentProvider 
{

      protected override void CreateChildControls(){.............}
      public WebPartContextualInfo WebPartContextualInfo
      {
            get
            {
                // get default current view webart (WebPartWPQ2)
                ListViewWebPart listView = this.WebPartManager.WebParts
                     .OfType<ListViewWebPart>().FirstOrDefault();
                // use reflection to get non-public member containing contextualinfo
                var t = listView.GetType();
                WebPartContextualInfo oViewInfo = (WebPartContextualInfo)t.InvokeMember("Microsoft.SharePoint.WebControls.IWebPartPageComponentProvider.WebPartContextualInfo", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.GetProperty, null, listView, new object[] { });

                return oViewInfo;
            }
        }
        protected override void OnPreRender(EventArgs e)
        {

            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            // Ensure ribbon exists.
            if (ribbon != null)
            {
                // Load dependencies if not already on the page.
                ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Ribbon.js", false, true);
            }
            base.OnPreRender(e);
       }
}

A great solution is to grab the contextualInfo for the main webpart on your view page.

public class MyView : WebPart, IWebPartPageComponentProvider 
{

      protected override void CreateChildControls(){.............}
      public WebPartContextualInfo WebPartContextualInfo
      {
            get
            {
                // get default current view webart (WebPartWPQ2)
                ListViewWebPart listView = this.WebPartManager.WebParts
                     .OfType<ListViewWebPart>().FirstOrDefault();
                // use reflection to get non-public member containing contextualinfo
                var t = listView.GetType();
                WebPartContextualInfo oViewInfo = (WebPartContextualInfo)t.InvokeMember("Microsoft.SharePoint.WebControls.IWebPartPageComponentProvider.WebPartContextualInfo", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.GetProperty, null, listView, new object[] { });

                return oViewInfo;
            }
        }
        protected override void OnPreRender(EventArgs e)
        {

            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            // Ensure ribbon exists.
            if (ribbon != null)
            {
                // Load dependencies if not already on the page.
                ScriptLink.RegisterScriptAfterUI(this.Page, "SP.Ribbon.js", false, true);
            }
            base.OnPreRender(e);
       }
}
北恋 2024-12-20 20:06:26

下面的版本使用 SharePoint 的按需脚本而不是 100 毫秒超时或 jquery。我认为这更可靠,因为它是在功能区初始化后准确执行的。

SP.SOD.executeOrDelayUntilScriptLoaded(function () {
    //using setTimeout to ensure it will be executed after the code of sp.ribbon.js has done its initialization
    setTimeout(function () {
        //try to focus the default webpart so the ribbon will show
        var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
        if (elem != null) {
            var dummyevent = new Array();
            dummyevent["target"] = elem;
            dummyevent["srcElement"] = elem;
            WpClick(dummyevent);
        }
    }, 0);
}, "sp.ribbon.js");

Below a version using SharePoint's Script On Demand instead of 100ms timeout or jquery. I think thats more solid, cuz it is exactly executed after the ribbon is initialized.

SP.SOD.executeOrDelayUntilScriptLoaded(function () {
    //using setTimeout to ensure it will be executed after the code of sp.ribbon.js has done its initialization
    setTimeout(function () {
        //try to focus the default webpart so the ribbon will show
        var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
        if (elem != null) {
            var dummyevent = new Array();
            dummyevent["target"] = elem;
            dummyevent["srcElement"] = elem;
            WpClick(dummyevent);
        }
    }, 0);
}, "sp.ribbon.js");
难如初 2024-12-20 20:06:26

与 Thorstens 解决方案类似,我使用 jQuery 在 mouseenter 事件上触发 WpClick 函数。这种方法还解决了当用户第一次进入页面并尝试使用其中一个菜单时完整工具栏崩溃的问题。如果需要,您可以捕获页面上任意数量的 Web 部件的事件气泡。例如:

$("body").on("mouseenter","#MSOZoneCell_WebPartWPQ2,#MSOzoneCell_WebPartWPQ3, . . . etc.",function() {
  WpClick(event);
});

其中“body”可以是您想要的任何父元素,其中包含悬停时要自动选择的 Web 部件。

当仅关注一个 Web 部件时,或者为了在大页面上获得最佳性能,您还可以直接在区域上设置事件。

$("#MSOZoneCell_WebPartWPQ2").attr("onmouseenter","WpClick(event)");

或者如果 jQuery 不可用

var el = document.getElementById("MSOZoneCell_WebPartWPQ2"); 
if(el != null) {
  el.setAttribute('onmouseenter','WpClick(event);');
}

(可选),您仍然可以通过手动触发事件来强制功能区在页面加载之后和用户悬停之前显示。只需在附加上述事件后包含适当的代码即可。例如使用 jQuery

$("#MSOZoneCell_WebPartWPQ2").mouseenter();

Similar to Thorstens solution, I use jQuery to fire the WpClick function on the mouseenter event. This approach also handles the issue where the Full Toolbar freaks out when a user first enters a page and tries to use one of the menus. You can trap the event bubble for any number of web parts on the page if desired. For example:

$("body").on("mouseenter","#MSOZoneCell_WebPartWPQ2,#MSOzoneCell_WebPartWPQ3, . . . etc.",function() {
  WpClick(event);
});

Where "body" could be any parent element you want that contains the web parts to auto select when hovering.

When only one web part is of concern, or for optimal performance on large pages you could also set the event directly on the zone.

$("#MSOZoneCell_WebPartWPQ2").attr("onmouseenter","WpClick(event)");

or if jQuery is not available

var el = document.getElementById("MSOZoneCell_WebPartWPQ2"); 
if(el != null) {
  el.setAttribute('onmouseenter','WpClick(event);');
}

Optionally, you can still force the Ribbon to appear after the page loads and before a user hovers by triggering the event manually. Just include the appropriate code after attaching the event above. e.g. using jQuery

$("#MSOZoneCell_WebPartWPQ2").mouseenter();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文