Access ASP.NET Application Settings in JavaScript [How-To]

14 November 2007 - 01:17 PM by Chris

Let's suppose you have a value that you are storing in the web.config for a given website. And let's further suppose you have some nifty JavaScript that needs to access that value. Here's how you do it.

First you need to assign that value to a protected string in your C# (or other preferred language) code like this:

protected string myValue = ConfigurationSettings.AppSettings["myValue"].ToString();

Then in JavaScript, you can use the variable just like you would do old-school inline classic ASP:

var myValue = "<%=myValue%>";

Enjoy.

Digg It!DZone It!StumbleUponTechnoratiRedditDel.icio.usNewsVineFurlBlinkList

Categories: ASP.NET
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Add comment


(Will show your Gravatar icon)  

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

17 November 2008 - 10:21 PM