We help IT Professionals succeed at work.
Get Started

Capturing App.Settings key on aspx  (vb) page and then passing to external javascript on an onclick event.

77 Views
Last Modified: 2020-03-19
Hello All:

I have a classic web forms asp (vb) web application that I am working with.  I have one page that I would like to embed a value from my web.config's app.settings.  this page references an external js file.  What I am ultimately trying to do is pass the value from app.settings to the js file on an onclick event.  The app.settings key holds the value of the current server, so I have transforms set to update the web.config with the correct server name when the application runs.

So in my app.settings I have:
<add key="CurrentServer" value="ProductionServer"/>

What I was trying to do was something like this:
<input type="hidden" id ="CurrentServer" value="<%$ AppSettings: CurrentServer %>" />

My reasoning behind this approach is then in the external file, I could target this input by doing something like:

let currentServer = document.getElementById('CurrentServer').value

When I run the page, I receive the following error:
Literal expressions like '<%$ AppSettings: CurrentServer %>' are not allowed. Use <asp:Literal runat="server" Text="<%$ AppSettings: CurrentServer%>" /> instead.

Can someone please steer me in the right direction?  Would a server control be more appropriate?  If so, how would I interrogate the rendered control using JavaScript once the onclick even is fired that triggers the javascript code?

Many thanks for any assistance!

Juan
Comment
Watch Question
Continuous Process Improvement Lead
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE