I have a need for generating JavaScript on the server. I can do this by using ASPX pages to template JavaScript but I'm getting warnings and I don't benefit from syntax hilighting which I would like. Is there a way to tell the .Net environment/Visual Studio that a certain ASPX page is supposed to output non-HTML text?
The reason for this is localization. My localized strings come from the server and I need these in JavaScript constructs on the pages. The easiest way I came up with is to have one JS file (I'll call it l18n.js for now) which defines the localized strings in a JSON object.
l18n = {
OK: <%= GetString("OK") %>,
Cancel: <%= GetString("Cancel") %>,
ConfirmDialog: {
Title: <%= GetString("ConfirmTitle") %>,
Message: <%= GetString("ConfirmMessage") %>
}
// .. etc.
}
This lets me use the localized strings in other parts of the UI
var okButton = $('<button>' + l18n.OK + '</button>')
But as said, just throwing the JavaScript inside an ASPX page, l18n.js.aspx, results in warnings and doesn't provide syntax hilighting. Is there a better way which would at least get rid of the warning? The current one is
Generation of designer file failed: Exception from HRESULT: 0x80042929
And in case it matters the project is built on top of .Net 2.0
Clarification
The language isn't user chosen so it shouldn't change all the time and I should be able to use the language value as the ETag so caching shouldn't be that big of an issue. From the browser perspective I'd consider the templated JS a static file just like rest of the files. I just don't want to declare the ~10 static JS files separately if I can automate it.