Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
110
rated 0 times [  114] [ 4]  / answers: 1 / hits: 17539  / 15 Years ago, fri, june 26, 2009, 12:00:00

I have web.config with the given value:



<appSettings>
<add key=vDirectory value=fr />
<add key=BookingSummaryPage value=/pli/forms/BookingSummary.aspx />
</appSettings>


Now I want to read the value of vDirectory through java script.



I am using below code:



<script language=javascript type=text/javascript>

function test()
{
var t='<%=ConfigurationManager.AppSettings(vDirectory).ToString() %>'
alert(t);
}
</script>

<input type=button value=Click Me onclick=test(); />


The error generated is:



Error 'System.Configuration.ConfigurationManager.AppSettings' is a 'property' but is used like a 'method' 

More From » javascript

 Answers
61

Edit: this doesn't answer your first issue, but still applies after you fix that. If vDirectory was something like c:new folder you'd end up with a newline in t.



I'm not sure what language you're using but you want to run the string though addslashes() (or the equivalent in your language) before you print it out like that:



var t='<%=addslashes(ConfigurationManager.AppSettings(vDirectory).ToString()) %>';


Or even better, JSON encode it if there's a function for that:



// Note no quotes as json_encode will add them
var t=<%=json_encode(ConfigurationManager.AppSettings(vDirectory).ToString()) %>;

[#99236] Monday, June 22, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kinsley

Total Points: 352
Total Questions: 84
Total Answers: 94

Location: Denmark
Member since Tue, Jul 19, 2022
2 Years ago
;