标识符在从web.config读取键值时在aspx页面中预期出现错误javascript [英] Identifier expected error javascript in aspx page while reading key value from web.config

查看:70
本文介绍了标识符在从web.config读取键值时在aspx页面中预期出现错误javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用.aspx页面中的javascript从web.config读取键值。此页面包含在母版页中,脚本块添加在我的aspx页面的ContentPlaceHolder标记中,如下所示;这个问题在此之前被问到 asp。 net - 如何在aspx页面的javascript中读取web.config中的值 - Stack Overflow [ ^ ]但是没有明确的解决方案。有人建议返回服务器端,但我试图避免返回服务器以加速用户在页面上的工作......所以下面是我的代码:



I am trying to read key value from web.config using javascript in my .aspx page. This page is included in a master page, the script block is added in the ContentPlaceHolder tag in my aspx page as below; This question was asked before here asp.net - how to read values from web.config in javascript in aspx page - Stack Overflow[^] but there was no clear solution. Someone suggested returning to server side but I am trying to avoid returning to server in order to accelerate user's work on the page ... So below is my code:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <script type="text/javascript">

        function CheckCountry() {
          var country =   '<%=System.Configuration.ConfigurationManager.AppSettings["LoginCountry"].ToString() %>';
          alert(country);
       }

       window.onload = CheckCountry; 

       </script>       
   </asp:Content>





但是每当我尝试运行我的项目时,我都会收到此错误(预期标识符)在Visual Studio 2010的列表错误框中。可能是什么问题?我如何解决这个问题并从我的aspx页面中的web.config获取国家/地区的价值?



我尝试了什么:



我也试过这个



But whenever I try to run my project I get this error (Identifier expected ) in the List Error box in visual Studio 2010. What could be the problem? How can I solve this and get the value of country from web.config in my aspx page?

What I have tried:

I have tried also this

'<%=ConfigurationManager.AppSettings["LoginCountry"].ToString() %>'



但不起作用,抛出相同的错误...


but didn't work, same error was thrown ...

推荐答案

看就像你使用vb.net而不是c# - bracket []



这是vb.net的正确语法 - 圆括号()



Look like you using vb.net instead of c# -- brackets []

Here is the correct syntax for vb.net -- Parentheses ()

var country =  System.Configuration.ConfigurationManager.AppSettings("LoginCountry").ToString()





顺便说一句,我确实在vb.net项目VS2010中使用[]的代码获得了相同的错误Identifier expected。用括号替换括号会使错误消失。所以,我假设您的项目使用的是VB.NET语言。



By the way, I did get the same error "Identifier expected" using the code with [] in vb.net project VS2010. Replacing the brackets with parentheses make the error go away. So, I'm assuming that your project is using VB.NET language.


这篇关于标识符在从web.config读取键值时在aspx页面中预期出现错误javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆