5

i want to have retrieve a "imagetype" from appsettings in my web.config in javascript . how can i do that?

2 Answers 2

8

You can use following code in your page markup:

<script language="JavaScript" type="text/javascript">
var type = '<%= ConfigurationManager.AppSettings["imagetype"] %>';
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

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>

1 Comment

@ŁukaszW.pl, true, but the general gist is the same. For some reason my eyes stopped reading after "asp.net" - a long day today! =)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.