First of all, you should understand that you never pass any values between C# and JavaScript, because they have very different nature and also work on different sides: C# on the server, JavaScript on the client. In the case you are interested in, you simply generate a whole page on the server side and sent it to the client in HTTP response. And the generated page can have JavaScript in it, as well as other stuff. From the standpoint of JavaScript, you simply hard-coded a JavaScript constant into the code, no matter what it was in C#.
Getting the idea?
Something like:
var helloFromAspNet <%= MyCSharpClass.MyStaticValue.ToString(); %>
or, to ensure the output of
MyCSharpClass.MyStaticValue
is HTML-encoded:
var helloFromAspNet =<%: MyCSharpClass.MyStaticValue.ToString(); %>
Please see:
http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx[
^].
—SA