2

I have a javascript code in the aspx file.

In my script function, I am trying to read the 'SiteRootURL' value from the web.config as:

var k = '<%=ConfigurationManager.AppSettings["SiteRootURL"].ToString() %>'
     alert(k);

This is not working. When I add above code, I get blue squirkly lines at the top of my aspx page - <%@Page...%> which says - Identifier Expected'

When I remove the above line, the code runs fine. Please help me. What am I doing wrong? How can I read the value form the web.config in javascript.

1
  • PLease let us know how you solved this problem, thanks Commented Mar 14, 2017 at 12:33

1 Answer 1

0

You can make a function on your code behind file like this:

protected static string GetAppSettingsValue()
{
    return ConfigurationManager.AppSettings("SiteRootURL").ToString();
}

And then call it on your javascript like so

<script type="text/javascript">
    alert('<%=GetAppSettingsValue%>');
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

I dont see the error. When I run the application and go that page. I see a custom application error page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.