?
Solved

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

Posted on 2014-02-04
1
Medium Priority
?
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 1260 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 22 hours left to enroll

777 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