javascript - Accessing ConfigurationManager.AppSettings in Java script -
i had javascript code in aspx file
page.aspx
<asp:content id="content1" contentplaceholderid="head" runat="server"> ----some code---- added after suggestion 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>
now moved code seprate .js file , included reference in javascript file.now not able access it.it coming "'<%=configurationmanager.appsettings["gaaccountid"]%>']"
how value it.
<%=configurationmanager.appsettings["gaaccountid"]%>
work when using in aspx
file. not evaluated when using in external js file.
you can decalre variable in aspx page
<script type="text/javascript"> var gaaccountid = '<%=configurationmanager.appsettings["gaaccountid"]%>'; </script>
use gaaccountid
variable in js file
Comments
Post a Comment