Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

How to read web config value in javascript ? i am try following ways,but it replay as it is, i mean in single quots what i give,
"<%=ConfigurationSettings.AppSettings("UserManual").ToString() %>"
my web config values is
XML
<add key="Version" value="8.5" />



JavaScript
 var k = '<%=ConfigurationSettings.AppSettings("Version").ToString() %>';
 alert(k);

var k1 = '<%=ConfigurationSettings.AppSettings["Version"].ToString() %>';
alert(k1);


var k2 = '<%=ConfigurationManager.AppSettings("Version").ToString() %>';
 alert(k2);

var k3 = '<%=ConfigurationManager.AppSettings["Version"].ToString() %>';
alert(k3);


I am try this link but same Read Configuration Settings of Web.config using Javascript[^]


pls reply me asap

Regards
Aravind
Posted
Comments
Wombaticus 14-Jun-15 15:27pm    
What .NET version are you using?
Aravindba 24-Aug-15 2:32am    
.net frame work version is 4.0

1 solution

First, I assume you have
VB
<add key="Version" value="8.5" />

in the appSettings section of your web.config file...

Then, the first of your lines above
VB
var k = '<%=ConfigurationSettings.AppSettings("Version").ToString() %>';

should work in .NET 2.0. In higher versions use the following:
VB
var k = '<%= System.Configuration.ConfigurationManager.AppSettings("Version").ToString()%>';
 
Share this answer
 
Comments
Aravindba 14-Jun-15 21:33pm    
Hi,Thank you for ur reply,stil i get what i give inside single quotes,the same word appear in alert msg,it never show what i give value in web config,for u refernce here i attach screenshot link http://prntscr.com/7h22wh ,i am use .net 4.0.
I am try with square bracket also,but still same
Wombaticus 16-Jun-15 3:31am    
I don't know what to say, I'm afraid - the above works for me. As an alternative to using appSettings in web.confog to hold such values thogh, you may want to consider using Application variables in a global.asax file. Set them in Application_Start - eg:
Application("Version") = "8.5"
and then you can read them anywhere you want in code behind using
... = CStr(Application("Version"))
or in JavaScript
... = '<%= CStr(Application("Version")) %>';
Aravindba 21-Jun-15 21:31pm    
Hi,we change that value after deploy in server,so we use web config,bcz in web config we add sql connection string,after deploy in server we change the server sql ,if we add in global.asax,how can change after deploy in server ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900