I am unsuccessful in accessing application state variable in javascript.
I declared the app state variable as,
Application["MYVAR"] ="My Variable";
JS:
var _myjsvar = <%='Application["MYVAR"]'%>
alert(_myjsvar);
But I don't get the value in JS alert. Any help, appreciated.
This should work as long as it is in a page executed by server ( ex :your aspx view etc..)
var _myjsvar = '<%= Application["MYVAR"] %>';
alert(_myjsvar);
If it is a razor view where you want to access the Application variable, you can do this.
<script>
var _myjsvar = "@HttpContext.Current.Application["MYVAR"]";
alert(_myjsvar);
</script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.