Access Session value in JavaScript function in ASP.Net

Last Reply 6 months ago By onais

Posted 6 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 >

}

 

You are viewing reply posted by: onais 6 months ago.
Posted 6 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>