Page view counter

Reading from web.config

Last post 02-13-2009 4:55 PM by asplikebutter. 15 replies.

Sort Posts:

  • Reading from web.config

    02-28-2008, 3:28 AM
    • Loading...
    • samerh
    • Joined on 04-04-2007, 11:46 AM
    • Posts 93
    • Points 28

    Hi all, I am reading from web.config a value on onbeforeunload in a master page

    <body onbeforeunload="Window_OnBeforeUnload();" style="left:0; top:0; right:0; bottom:0">

    web.config <appSettings>

    <add key="PathLogout" value="http://10.1.5.29/CID/Logout.aspx"></add>

    </appSettings>

    In the javascript i trying to read PathLogOut using

    var MyVar = '<%=AppSettings:PathLogout%>';

    iam getting this error

    Compiler Error Message: BC30451: Name 'AppSettings' is not declared.


    Any Ideas and thanks in advance

     

     

     

     

     

  • Re: Reading from web.config

    02-28-2008, 3:53 AM
    • Loading...
    • vik20000in
    • Joined on 12-30-2005, 6:02 AM
    • Kolkata
    • Posts 2,641
    • Points 16,675
    • TrustedFriends-MVPs

    I dont think you can access value sin web.config from javascript

    Vikram
    www.vikramlakhotia.com


    Please mark the answer if it helped you
  • Re: Reading from web.config

    02-28-2008, 3:58 AM
    • Loading...
    • Andreas Paulsson
    • Joined on 02-22-2008, 8:03 AM
    • Borås, Sweden
    • Posts 125
    • Points 1,040

    When using expression builders in an aspx page, use the <%$ expression prefix: expression value %> syntax. See http://www.beansoftware.com/ASP.NET-Tutorials/Expression-Builder.aspx for more details.

    So You should use  

    var MyVar = '<%$ AppSettings:PathLogout%>';

    instead.

     

    Andreas Paulsson
    Software Developer
    cimkey AB
  • Re: Reading from web.config

    02-28-2008, 4:07 AM
    • Loading...
    • samerh
    • Joined on 04-04-2007, 11:46 AM
    • Posts 93
    • Points 28

    Iam getting this error

    Parser Error Message: Literal expressions like '<%$ AppSettings:PathLogout%>' are not allowed. Use <asp:Literal runat="server" Text="<%$ AppSettings:PathLogout%>" /> instead.

  • Re: Reading from web.config

    02-28-2008, 4:16 AM
    • Loading...
    • Mulukutla
    • Joined on 10-19-2007, 7:08 AM
    • Hyderabad
    • Posts 88
    • Points 271

    hey, try giving like this Configuration.ConfigurationManager.AppSettings:"KEY" in text binding.

    i think this may work for u.

    Regards,

    MulukutlaCool 

  • Re: Reading from web.config

    02-28-2008, 4:30 AM
    • Loading...
    • samerh
    • Joined on 04-04-2007, 11:46 AM
    • Posts 93
    • Points 28

    Iam using this in my javascript but still getting same error :(

     alert ("test");
     var MyVar = '<%$ System.Configuration.ConfigurationSettings.AppSettings:PathLogout%>'; 
    alert(MyVar.value);

  • Re: Reading from web.config

    02-28-2008, 4:39 AM
    • Loading...
    • samerh
    • Joined on 04-04-2007, 11:46 AM
    • Posts 93
    • Points 28

    i have tried to add a hidden field and read the key from it

    <asp:HiddenField ID="HiddenField1" runat="server" Value="<%$AppSettings:PathLogout %>" />

    then in JS

    var myVar = document.getElementById('<%= HiddenField1.ClientID %>').value;

    but giving an error

    The expression prefix 'System.Configuration.ConfigurationManager.AppSettings' was not recognized.  Please correct the prefix or register the prefix in the <expressionBuilders> section of configuration.

    please note that i have added

    <add namespace="System.Configuration.ConfigurationManager"/>

    in namespaces in web.config and code behind of the page

  • Re: Reading from web.config

    02-28-2008, 4:41 AM
    • Loading...
    • Andreas Paulsson
    • Joined on 02-22-2008, 8:03 AM
    • Borås, Sweden
    • Posts 125
    • Points 1,040

    Are You using .NET 2.0 or later?

    Use

    alert ("test");
    var MyVar = '<%$ System.Configuration.ConfigurationManager.AppSettings:PathLogout%>';
    alert(MyVar.value);

    instead. 

    Andreas Paulsson
    Software Developer
    cimkey AB
  • Re: Reading from web.config

    02-28-2008, 4:54 AM
    • Loading...
    • samerh
    • Joined on 04-04-2007, 11:46 AM
    • Posts 93
    • Points 28

    iam using 2.0

    i did try it but it didnt work. Are u sure that is is working?

    used this

    var MyVar = '<%$ System.Configuration.ConfigurationManager.AppSettings:PathLogout%>';

    alert(MyVar.value);

     

  • Re: Reading from web.config

    02-28-2008, 5:39 AM
    Answer
    • Loading...
    • JRICE
    • Joined on 05-11-2006, 12:52 AM
    • Lebanon-Beirut
    • Posts 667
    • Points 2,176
    function test() { var t='' alert(t); }

    Heres a sample on how you read appsettings from javascript 

    <script type="text/javascript">
    function
    test()
    {
    var t='<%=ConfigurationManager.AppSettings("test").ToString() %>'
    alert(t);
    }
    </script>
    <input type="Submit" value="Save" onclick="test()" />

    Web.Config
    <
    appSettings>
    <
    add key="test" value="test2"/>
    </
    appSettings>

    HTH

    Please remember to "Mark As Answer" if this post answered your question!

    Bilal Shouman - MCAD.NET

    |My Blog|
    ---------------------------------


  • Re: Reading from web.config

    02-28-2008, 6:12 AM
    • Loading...
    • samerh
    • Joined on 04-04-2007, 11:46 AM
    • Posts 93
    • Points 28

    I need to read the value of the key in a javascript found in my master page.

    i am writting this to read the PathLogout:

    var t='<%=System.Configuration.ConfigurationManager.AppSettings("PathLogout").ToString() %>';

    window.open(t);

    when running my site it gives an error:

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

     

  • Re: Reading from web.config

    03-14-2008, 1:46 AM

    Try this 

    ClientScript.RegisterClientScriptBlock(this.GetType(), "maxAge", "<script language='javascript'>var maxAge='" + ConfigurationManager.AppSettings["test"].ToString() + "';</script>");

     

    Thanks

    Arun

  • Re: Reading from web.config

    04-02-2008, 5:06 AM
    • Loading...
    • NHOQUE
    • Joined on 04-02-2008, 9:00 AM
    • Kumamoto, Japan
    • Posts 814
    • Points 4,965

    You may try the following:

    I tried it in my ASP.NET 2.0 and got the result. 

    var MyVar='<%= System.Configuration.ConfigurationManager.AppSettings["PathLogout"].ToString()%>'

    HOQUE MD.NAZMUL
    [document.getReaders]
  • Re: Reading from web.config

    11-21-2008, 5:37 AM
    • Loading...
    • vaibhavgangal
    • Joined on 09-25-2007, 8:27 AM
    • Mumbai
    • Posts 32
    • Points 39

    Hi,

    I have tried following code but gave error "Identifier expected".

    var imgval = '<%=System.Configuration.ConfigurationManager.AppSettings["ImageSrcToken"].ToString() %>';

    Any idea what this error is?

     

    Regards,

    Vaibhav

     

  • Re: Reading from web.config

    11-21-2008, 6:15 AM
    • Loading...
    • Andreas Paulsson
    • Joined on 02-22-2008, 8:03 AM
    • Borås, Sweden
    • Posts 125
    • Points 1,040

     Make sure that you have a reference to System.Configuration in your project.

    Andreas Paulsson
    Software Developer
    cimkey AB
Page 1 of 2 (16 items) 1 2 Next >