Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

444
Views
Access Session Variable in javascript

I need to access a Session Variable in javascript. I tried all the examples but none of them are working. I do not know what I am doing wrong.

I have the following:

In my Account controller after successful login I set my Session Variable like this.

 HttpContext.Session.Add("IsShowStartPopUp", true);

In my landing view I try to access the session variable like this:

<script type="text/javascript">
 
var IsShowStartPopUp = '<%= Session["IsShowStartPopUp"] %>';

</script>

My result is:

'<%= Session["IsShowStartPopUp"] %>'

Am I missing something?

Thanks you.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

In your code, you should not use contention while trying to access a dynamic value '<%= Session["IsShowStartPopUp"] %>' . Otherwise, it'll be considered as a string.

You can use sessionStorage.

Example:

<script> 
sessionStorage.setItem('mysession','value');

alert(sessionStorage.getItem('mysession'));
</script>
about 4 years ago · Juan Pablo Isaza Report

0

I found this answer:

No, session state is server-side.

I then use the following:

I still set the session variable in the controller when the user log in

HttpContext.Session.Add("IsShowStartPopUp", true);

I then created the following in my MVC view:

@if (HttpContext.Current.Session["IsShowStartPopUp"].ToString() == true)
{
    HttpContext.Current.Session["IsShowStartPopUp"] = false;
    <script type="text/javascript">
        window.onload = function () {ShowPopup();}
    </script>
};

This solved my issue and if there is any suggestions you are more that welcome to comment.

Thanks

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!