Is it possible to create a javascript file with some C# variables? Something like this:
var foo = <%= CODE_VALUE.foo %>;
Or do I have to create them in a usercontrol.ascx which I include in the <head> section?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can not have this code inside the .js file because is not compile by asp.net and so is not translate the
CODE_VALUE.foointo code.what you can do is to place this variables just before load this .js file that you won to use, and set them on any aspx or user control.
For example
alternative you can create a handler that read javascript files, include your custom variables and create a full javascript code as you like, and send it as javascript one.
Some relative: How to get asp.net client id at external javascript file