locked
Get the key value of web.config in javascript. RRS feed

  • Question

  • User-73514677 posted

    Hi,

    I have set a key in appsettings in the web.config.

    For example:

    <add key="AllowEdit" value="false"/>


     

    I want to access the value "false" in external javascript file.

    How to access the key value in javascript.

    Thank you

    Wednesday, July 15, 2009 4:55 AM

Answers

  • User2130758966 posted

    You cant do it directly. The workaround for this would be to do the following:

    • At page load on the server side you extract the appsetting
    • You register a client script block to output the appsetting as a javascript variable
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 15, 2009 5:52 AM

All replies

  • User-1179452826 posted

     I'd recommend you create a WCF service which would proxy the app configuration. Your javascript would then simply call the web service.

    Wednesday, July 15, 2009 5:40 AM
  • User-8554525 posted

    Write a function and add a parameter to the function.

    Call the function in some button click / link click / ... event.

    Wednesday, July 15, 2009 5:45 AM
  • User-73514677 posted

    Hi,

    I am using c# and ASP.NET 2.0. I dont want a create a webservice to read the app configuration.

    Is there any other way to access the value in javascript

     

    Wednesday, July 15, 2009 5:52 AM
  • User2130758966 posted

    You cant do it directly. The workaround for this would be to do the following:

    • At page load on the server side you extract the appsetting
    • You register a client script block to output the appsetting as a javascript variable
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 15, 2009 5:52 AM
  • User-73514677 posted

    Hi,

    Thank you very much for the reply.

    I added the key in a hidden field and accessed it in javascript file.

    Wednesday, July 15, 2009 6:34 AM