Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Somehow transfer session variable on client side and use it with javascript?

Has somebody found the way to somehow access session variables through javascript on client side? I need to put some text in header of each page that should be retrieved from controller/or session set by server side.
Any idea or walkaround solutions?

Tnx in advance.
1 person has
this question
  • This reply was removed on 2020-01-03.
    see the change log
  • uremovic

    It is possible, write a code controller that queries session variables, and call it from the client side using REST or $app.execute.

    Best regards,

  • (some HTML allowed)
    How does this make you feel?
    Add Image

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated

  • Roberto, tnx for the tip, but I have figured it out meanwhile. I haven't tried $app.execute method yet.

    Here is one possible solution (although it is not the best because changes must be done after each generation of project):

    In Main.master file, after body element put the following line:
    <input type="hidden" id="hdnSession" value="<%=Convert.ToString(Session["MySessionVar"])%>"/>

    Then, when you want to get this variable through javascript, call it with:

    E.g. I use menu title element to put session value in it (in touch.js):
    menuStripInfo.title = $('<span class="app-menu-strip-title"/>').appendTo(menuStrip.addClass('app-menu-strip-has-title')).text($("#hdnSession")[0].value);
  • (some HTML allowed)
    How does this make you feel?
    Add Image

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated