1

I have some javascript code that has in it localized messages that i pull from my resource files. My problem is that if i include my javascript files like...

<script scr="..." type="text/javascript"/>

in my masterpage for example, then the <%= Resources... %> code is not running on view rendering. My current way of resolving this problem is by including the full code inside script tags in my masterpage, but i don't like it.

Any better suggestions?

1
  • To get this right, you mean inside your .js file you have serverscript tags like these <%=Resources.MyMessage %>? Commented Dec 13, 2010 at 12:08

2 Answers 2

3

You need to close out all script tags as such for IE to accept the JavaScript:

<script>....</script>

Not

<script .... />
Sign up to request clarification or add additional context in comments.

1 Comment

thx for the suggestion but thats not what i meant as my problem.
0

Understanding the problem

Inline asp.net tags (e.g. '<%= %>' are parsed at runtime when the server renders your page. In order for ASP.Net to be able to parse documents it needs to be specified by the webserver that the extension is handled by the aspnet_isapi ISAPI extension.

The regular JavaScript files, to which you are adding asp.net code, will never run through this extension and thus will never be 'compiled' properly.

Now is there a solution?

Mads Kristensen has written a blogpost about this problem in 2008. It is still valid afaik and should do exactly what you need. See http://madskristensen.net/post/Localize-text-in-JavaScript-files-in-ASPNET.aspx

He uses the .axd extension which is also handled by the aspnet_isapi ISAPI extension.

Another very good post which addresses the problem more specifically for asp.net mvc can be found here: http://afana.me/post/aspnet-mvc-internationalization.aspx

Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.