Solved

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

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 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