访问ConfigurationManager.AppSettings在Java脚本的 [英] Accessing ConfigurationManager.AppSettings in Java script

查看:98
本文介绍了访问ConfigurationManager.AppSettings在Java脚本的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在aspx文件这个JavaScript code

I had this javascript code in aspx file

Page.aspx

Page.aspx

<asp:Content ID="Content1" ContentPlaceHolderID="Head" runat="server">
 ----some code----
 added after suggestion from Satpal
 <script type="text/javascript">
var GAAccountId = '<%=ConfigurationManager.AppSettings["GAAccountId"]%>';
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<%--<script type="text/javascript">
        debugger;
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', '<%=ConfigurationManager.AppSettings["GAAccountId"]%>']);
        _gaq.push(['_setDomainName', 'auto']);
        _gaq.push(['_setAllowLinker', true]);
        _gaq.push(['_trackPageview', '/Register']);
        _gaq.push(['_trackPageLoadTime']);

        (function () {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();

    </script>--%>
</asp:Content>

现在我搬到这个code到seprate .js文件,其中包括在JavaScript file.Now我不能够访问it.it来了,因为它'&LT参考;%= ConfigurationManager.AppSettings [GAAccountId]%GT;']

Now I moved this code to seprate .js file and included the reference in javascript file.Now I am not able to access it.it is coming as it "'<%=ConfigurationManager.AppSettings["GAAccountId"]%>']"

如何从中获得价值。

推荐答案

&LT;%= ConfigurationManager.AppSettings [GAAccountId]%&GT; 会当你的工作在 ASPX 文件中使用它。当您在外部JS文件使用它,它不会被评估。

<%=ConfigurationManager.AppSettings["GAAccountId"]%> will work when you are using it in aspx file. It will not be evaluated when you are using it in external js file.

您可以做decalre在aspx页面的变量

You can do decalre a variable in aspx page

<script type="text/javascript">
    var GAAccountId = '<%=ConfigurationManager.AppSettings["GAAccountId"]%>';
</script>

在JS文件

使用 GAAccountId 变量

这篇关于访问ConfigurationManager.AppSettings在Java脚本的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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