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

On a webpart, when I am navigating away from the page the webpart is on, I need to abandon the session of that webpart.

I store values in the session that are used by the webpart. The webpart is also in more than one place on the site, so if I do not abandon the session of the current webpart, those values will be used by a different instance of the webpart.

Is there an event I can override to achieve this?

share|improve this question
up vote 0 down vote accepted

That depends on what you are trying to achieve. If you always want to wipe out the data whenever they leave a page then Angie's suggestion might work for you.

However, if you are simply trying to prevent multiple instances of the webpart from 'bleeding' into each other on different pages you could simply use a unique identifier (i.e. current page relative url, current page ID, current WebPart ID, etc) as part of the key for your session variables. That would preserve the proper state for each unique instance and it would also prevent users from having to re-enter data repeatedly as they browse back and forth through the site.

share|improve this answer
Hi, Thanks for your responses :) I will try the 'id' idea – Mahendran Govender Jun 11 '12 at 9:31
We have decided to go a different way (not using session vars), but using ids did work. Thanks! – Mahendran Govender Jun 12 '12 at 8:48

You can write PageMethods that will be called by the javascript. The PageMethod can reset the session variable.

share|improve this answer

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.