Does SharePoint support session variables that can be accessed by the client side? Using client side jQuery or JS or even placing code on an ASPX acsset attached to a webpart to set variable on the page in a web part that can be read by the jQ, JS, etc.

  • yes, SharePoint supports Session variables in client side
    – Gaurravs
    May 31, 2016 at 11:08

1 Answer 1


Define JavaScript variable like this:

<script type="text/javascript">
var myVariable = '<%= this.Session["VariableName"] %>';

In this example your variable will have string type. If it is e.g. integer, you don't need to use quotes ''. The idea is the same as described in this article: Pass locale of current web site (SPWeb) in SharePoint into JavaScript.

Note that you can't use this technique in separate .js files. You can only use it if JavaScript is embedded to the page as shown above. However it is not big limitation. You may define variable as shown above and pass it to the function which is defined in separate .js file.

You can also look at this post.

  • You may use HiddenField control to "send" value from server to client, where you can read it from JavaScript
  • Beware that by default Session variables (as in ASP.NET Session) are stored in memory so you will have separate variable instances on each SharePoint server. You need to separately configure it in web.config in order to persist Session variables in, e.g., DB to have farm wide session variables.
    – Jussi Palo
    May 31, 2016 at 12:06
  • was thinking just page level .. thanks for info @jussi Palo
    – Gaurravs
    May 31, 2016 at 12:12
  • If you are storing critical and sensitive data in session, do not use this method and it will be visible if you use developer tools in browser.
    Jul 26, 2018 at 17:18
  • Critical data is not supposed to be stored unless encrypted somehow
    – Gaurravs
    Jul 27, 2018 at 4:50

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.