You could also use the West Wind Web Toolkit by Rick Strahl, which has a REALLY nice component for this purpose.
Blog Entry:
http://www.west-wind.com/weblog/posts/2008/Feb/21/Embedding-ASPNET-Server-Variables-in-Client-JavaScript-Part-2[
^]
(I have no connection to Rick Strahl or West Wind, I just like the toolkit.)