Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
i want to store session info(from asp) in local storage and access in js and its working but

I want to store session info(from asp) in local storage and access in JS and its working but when for the first time I login the (local storage key value) "userStatus" which is "user" does not store in the local storage even no local storage is NOT created …. BUT when I go back from any page(after log out) to login and LOGIN AGAIN then the local storage is created... anyone have any idea what I am missing (is it post back issue??)

button Login

<div class="d-grid gap-2 pt-2">
                                    <asp:Button ID="Button1" runat="server" class="btn btn-secondary  " Text="Log In"  OnClick="btnLogIn_Click"  OnClientClick="checkStatus();" />
                                        </div>

asp Code where i am passing Session["role"] = "user" from login page.cs to masterpage variable

                if (dr.HasRows)
                {
                    if(dr.Read())
                    {
                        //Response.Write("<script> alert( 'the user  : "+dr.GetValue(8).ToString()+" Successfully Logged in')</script>");


                        Session["username"]=dr.GetValue(8).ToString();
                        Session["fullname"] = dr.GetValue(0).ToString();
                        Session["role"] = "user";
                       Site1.PublicSession=HiddenField1.Value = Session["role"].ToString();

                        Session["status"] = dr.GetValue(10).ToString();

                    }

                    ScriptManager.RegisterStartupScript(this, GetType(), "popup", "MyAlertFunOnSucc()", true);
                    Response.Redirect("homePage.aspx");


                }
                else
                {

                //    Response.Write("<script> alert('Invalid Login or Password ')</script>");
                    ScriptManager.RegisterStartupScript(this, GetType(), "popup", "MyAlertFunOnFailure()",true);
                    HiddenField1.Value = null;

                }

my Js function in the master page header

<script type="text/javascript">
        function checkStatus() {
            var printSession = '<%=PublicSession%>';
            console.log(printSession);
            if (printSession) {
                localStorage.setItem("userStatus", printSession);
            }
        }
    </script>
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda