SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question
up vote 1 down vote accepted

I had to do something similar recently when trying to hide the ribbon in SP 2010. I have a blog article about it here:

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.

share|improve this answer
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. – Steve Lineberry Jun 7 '12 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 Jun 7 '12 at 17:51
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? – Steve Lineberry Jun 7 '12 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 Jun 7 '12 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 Jun 7 '12 at 19:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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