[ACCEPTED]-Read web.config values from Javascript-asp.net

Accepted answer
Score: 13

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.

Score: 5

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>

More Related questions