i want to have retrieve a "imagetype" from appsettings in my web.config in javascript . how can i do that?
A:
Use the following:
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"];
You may find that for it to work you need to add a reference to System.Configuration.dll
if you don't already have one.
Create a new page, and in Page_Load put the line so that it all reads:
Response.Clear();
var value = System.Configuration.ConfigurationManager.AppSettings["imagetype"];
Response.Write(value);
Response.End();
You can now make an AJAX call to the page from Javascript, perhaps using ExtJs and the text will be returned to your javascript.
Alternatively, you could put the following into your page:
<script language="javascript" type="text/javascript">
var appSettingValue = '<%=System.Configuration.ConfigurationManager.AppSettings["imagetype"]%>';
// The variable "appSettingValue" will contain the string from your web.config
alert(appSettingValue);
</script>
Rob
2010-08-02 14:24:24
It's MVC... there is no Page_Load...
ŁukaszW.pl
2010-08-02 14:29:07
@ŁukaszW.pl, true, but the general gist is the same. For some reason my eyes stopped reading after "asp.net" - a long day today! =)
Rob
2010-08-02 14:35:10
+5
A:
You can use following code in your page markup:
<script language="JavaScript" type="text/javascript">
var type = '<%= ConfigurationManager.AppSettings["imagetype"] %>';
</script>
Pavel Morshenyuk
2010-08-02 14:27:31