I have a resource file in Asp.net and I am reading the value from there as follows
var val1 = '<% = Resources.Test.FirstValue%>'; //Hello
var val2 = '<% = Resources.Test.SecondValue%>'; //World
alert(val1);
alert(val2);
It does work properly. But Suppose I want to use the String.Format function in C# inorder to make it as “Hello – World” as under
var val3 = '<%= string.Format("{0} - {1}",<% = Resources.Test.FirstValue%>,<% = Resources.Test.SecondValue%> %>';
It is throwing some compile time error
Invalid expression term '<'
Invalid expression term '='
) expected
; expected
Invalid expression term ')'
Cannot I use a server side function like that way in Javascript . However, the below works
var val3 = '<%= string.Format("{0} - {1}","Hello","World") %>';
Well I know that the problem can be solve using javascript itself. I am just curious to see how to get the String.Format function of C# work in Javascript in conjunction with Resource file values.
So, please give the correction /solution pertaining to String.Format and Resource file values only.
Thanks a lot
You only need 1 set of
<%=and%>for this. You’re also missing the closing)forstring.Format.But, everything between a set of
<%=and%>is C#, which doesn’t support further use of these template operators. You only need these operators again after you’ve ended the previous set: