Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

442
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda