views:

516

answers:

3

I have used the embedded resource js file to reference the .resx file before.

(by including something like

[assembly: ScriptResource("Applications.Webs.Scripts.HelpModule.js",
 "Applications.Webs.Scripts.Resources.HelpResources", "Resource.HelpResources")]

in the code behind of the page, where HelpModule.js is a embedded resource)

I was wondering if I can access the .resx when the js is a content file? I have heard "no"s so far. Does any one know if this can be done?

Thanks for your replies in advance.

A: 

If your question is whether you can use values from the .resx in the JavaScript code, the answer is "not directly". You'll have to expose the resources from the resx as JavaScript variables that are emitted with your response and parsed by the browser in order to use them in your JS.

DDaviesBrackett
I was hoping there would be a "direct way" to do this. Thanks for your answer!
Kinokko
A: 

You could fudge this a little

Use a HttpModule to parse the JS just before its sent down to the client looking for 'Tags'.

When you encounter your Tag then replace it with the required value from the resx file...

I used a technique similar to this for localizing JS files recently...

Overflow
A: 

Alternatively, you might be able to use AJAX to muddy it up a bit. If you built a small method that was designed to dip into the resx file you could asynchronously dip. If you didn't want to use all of the Microsoft AJAX compiled stuff (for whatever reason), you could use a small AJAX engine (they're everywhere) and just wire it up to a .ashx handler. That way you could dip into the compiled .resx anytime you needed to. You'd just have to be willing to accept whatever connection latency AJAX might give you.

Joel Etherton