[ACCEPTED]-Read web.config values from Javascript-asp.net
Accepted answer
The <%= =>
tag is only going to execute if it 5 is within a .aspx
file. If you place it within 4 a .js file, then it will just be like any 3 other text. In order for your code to work, the 2 javascript you posted would have to be embedded 1 within the .aspx file.
After to put the values on the config file, on 5 the page that you will use the value put 4 the java script this way bellow: You will 3 access the value in the java script as a 2 global, not necessary to declare it.
on the 1 web config:
</appSettings>
<add key="varName" value="1" />
</appSettings>
on the html page:
<script>
var varName= '@System.Configuration.ConfigurationManager.AppSettings["varName"]';
</script>
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.