Display ribbon on page with multiple ListViewWebPart

Hello everyone,

Today I’ll talk about a code snippet I found for a discussion on msdn. (see the discussion here: http://social.msdn.microsoft.com/Forums/en/sharepoint2010programming/thread/0372bae3-6e10-4b1f-a77a-49c892086538)

The person wanted that the behavior of a standard ListViewWebPart list remains the same even if we added other webparts on the page.

After some research I came across this tip:


The proposed answer is to add a script in the page simulating a click on the ListViewWebPart.

Here’s the script:

setTimeout(function() {
    var elem = document.getElementById("MSOZoneCell_WebPartWPQ2");
    if(elem != null) {
        var dummyevent = new Array();
        dummyevent["target"] = elem;
        dummyevent["srcElement"] = elem;
}, 2000);

I tested it successfully on a team site by adding this code into a Content Editor Web Part on the page. I just changed the timeout to 2 so that it goes faster.

Well done to the person who found it!