Access Session value in JavaScript function in ASP.Net

Last Reply 10 months ago By onais

Posted 10 months ago

i am getting the value in Master Page

string ab = (string)Session["UserID"]; 

i want pass the "ab" variable  value to javascript function and

if (ab > 0)

{ No change

}

else

{

disable <li class >

}

 

Posted 10 months ago

C#

protected void Page_Load(object sender, EventArgs e)
{
    string ab = (string)Session["UserID"]; // Read session
    Session["myValue"] = ab;
}

 script

<script type="text/javascript">
    var yourSessionValue = '<%= Session["myValue"] %>';
    alert(yourSessionValue);
</script>