Is there a way to know when a webpart gets focused? I've look around, but couldn't find anything helpful.


1 Answer 1


I had to do something similar recently when trying to hide the ribbon in SP 2010. I have a blog article about it here: http://www.thelineberrys.com/default-category/option-to-show-the-sharepoint-2010-ribbon-when-hidden-by-default-2.html

I can tell you the function

function OnRibbonMinimizedChanged(ribbonMinimized) 

get's called when you click on a webpart. I had found another function when an item is selected but I don't remember what it was because the OnRibbonMinimizedChanged was the one I needed to tap into.

I hope this helps get you down the path you need. Thanks.

  • 1
    Oops, just realized that you said c# and I gave you a JS function. I don't think there is a c# event for when a webpart get's focused, only a JS event. Commented Jun 7, 2012 at 17:32
  • yeh...I can go with two functions, either when ribbon is shown for the webpart or when webpart comes in to focus....Both would mean the same thing, if webpart comes into focus, then the ribbon shows....But it has to be backend....I'm guessing it might not be possible because there is no postback....
    – harsimranb
    Commented Jun 7, 2012 at 17:51
  • 1
    Yes, you are correct about the postback. You could do what I did with a delegate function and override the ootb one. Then in your own method you could do an ajax call to something that can handle your server side code. What are you actually trying to accomplish? Commented Jun 7, 2012 at 18:00
  • I have a ribbon attached to the webpart...The ribbon's buttons disable/enable depending on the selections made inside the webpart (using javascript)....However, with two or more wps on the page, the ribbon doesn't get updated automatically when a different webpart is selected...I want to automatically update the ribbon when the wp gets focus....currenly im playing with your code, maybe I can get something to work...
    – harsimranb
    Commented Jun 7, 2012 at 18:08
  • Even though I didn't use your approach, you're answer helped me find my answer...I used EventBug in firefox to see which even gets fired when we click a webpart, then I overrided that event and made my custom call.
    – harsimranb
    Commented Jun 7, 2012 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.