SharePoint show Ribbon with multiple web pages per page

I created a sharepoint page with an xslt web part and a second web part that is not related to the question

When we add this second webpage, the ribbon bar is hidden and you need to click the webpage to show the ribbon again. By clicking on the website, we cannot ask our users, therefore I am trying to get a ribbon bar at any time with the context of our xslt listview website.

When looking for this problem, I found that when looking for this hidden reflector feed behavior in the SharePoint source code, it seems like this is a behavior developed by Microsoft, as shown below:

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

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

Is it possible for the tape to be visible with server-side code, or can I call the javascript code that is used when I click on a webpage to show the ribbon bar?

I think this is possible with javascript, because if you click on the xslt web page, the feed will be visible, but I will not be able to play the executable code.

+4
source share
5 answers

you can use JavaScript to reselect XSLTListViewWebPart so that the feed reappears.

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

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, MSOZoneCell_WebPartWPQ4 is my watchlist web part

+1
source

A great solution is to capture contextual information for the main web page on the watch 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); } } 
0
source

Like the Thorstens solution, I use jQuery to run the WpClick function in a mouseenter event. This approach also fixes an issue where the full toolbar gets confused, when the user first enters the page and tries to use one of the menus. You can optionally capture an event bubble for any number of web parts per page. For instance:

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

Where "body" can be any parent element that you want that contains web parts for automatic selection when you hover over.

When only one web part is disturbing or for optimal performance on large pages, you can also set an event directly in the zone.

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

or if jQuery is not available

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

If you wish, you can still make the feed appear after the page loads and before the user is guided by triggering the event manually. Just add the appropriate code after adding the event above. e.g. using jQuery

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

Lower version using SharePoint Script On Demand instead of 100 ms timeout or jquery. I think this is more solid, because it is exactly executed after the initialization of the tape.

 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"); 
0
source

Source: https://habr.com/ru/post/1379449/


All Articles