Reputation: 143
I have a page that uses an external javascript file. That file requires variables that are different in Dev, QA and production environments, causing me to need to maintain multiple copies of the same script file for each environment.
I'd prefer to maintain the values of these variables in web.config (perhaps appSettings section), and resolve these values at runtime, before streaming the .js file to the browser. Is there a way to do this?
Upvotes: 2
Views: 1111
Reputation: 10105
asp.net Can I inject configuration settings into javascript?
<script language="javascript" type="text/javascript">
var Publicvalue = abc();
function abc() {
Publicvalue = <%=MyProperty%>
alert(Publicvalue);
return Publicvalue;
}
</script>
<asp:Button ID="btn" runat="server" Text="efeded" OnClientClick="return abc();" OnClick="btn_Click" />
public int MyProperty
{
get
{
return 1;
}
}
Upvotes: 1