Tutorial :Calling global variables in the AppSettings from a Javascript function


In my javascript function I am trying to call my global variable that is currently defined in the webconfig file of my Asp.net project. What is the syntax for this? I've looked around and nothing seems to work so far. I've tried the following but I am not getting anything from it:


<appSettings>    <add key="var1" value="123456"/>  </appSettings>  


<script type="text/javascript">    function doSomething() {"<%= System.Configuration.ConfigurationManager.AppSettings['var1'].ToString(); %>"  };  </script>  


What do you expect to get from it? Even if you manage to get the value, the code doesn't do anything at all with it. It just declares a string literal and throws it away...

You can put the value in a Javascript variable like this:

<script type="text/javascript">  var var1 = '<%=System.Configuration.ConfigurationManager.AppSettings["var1"].ToString();%>';  </script>  

Now you can use that variable in your Javascript code.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »