Solved

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

Posted on 2014-02-04
1
224 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now