Solved

Adding Javascript to an ASP.NET page based on Environment Setting

Posted on 2014-02-04
1
228 Views
Last Modified: 2014-02-04
Hello,
I have a Web.Config App.Setting which holds the following

<appSettings>
  <add key="Environment" value="Development"/>
</appSettings>

I am then reading this value and depending the value I will read a particular JavaScript from a file.

i.e
<script src="~/Scripts/Development.js"></script>
or
<script src="~/Scripts/Test.js"></script>

etc
0
Comment
Question by:IandINSW
1 Comment
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 315 total points
ID: 39834453
If this is WebForms, in the code-behind create a protected property that exposes the setting, e.g.

protected string Environment
{
    get
    {
        return ConfigurationManager.AppSettings["Environment"];
    }
}

Open in new window


Then in the markup reference that property, e.g.

<script src="~/Scripts/<%= Environment %>.js"></script>

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question