[RESOLVED]How to access ASP.NET Global resource RESX file through Jquery

How to access ASP.NET Global resource RESX file through Jquery

I am changing the langauge in the Master page.

bharathi_m

I am changing the langauge in the Master page.

Changing language in asp.net does not require jquery.

If you want to use jquery for some reasons, then output resource strings into hidden span or div and refer to it from jquery.

<asp:Literal runat="server" ID="Literal1" visible="false" Text="<%$ Resources:String, MyResourceText%>" />
<input type="button" id="Button1" value="" />
<script type="text/javascript">
$(document).ready(function () {
// Update the buton text with the correct localised lookup
var ButtonText = ‘<%=Literal1.Text%>’;
$("#Button1").attr(‘value’, ButtonText );
});
</script>

Another way is to inject asp.net code in the script as 

<script language="javascript" type="text/javascript">
var MONTHS_SHORT1 = <%=GetGlobalResourceObject("Resource", "MONTHS_SHORT1") %>;
</script>

http://stackoverflow.com/questions/3649627/using-global-resource-in-javascript

Your answer is correct for single page.

But I am using a common js file for all the aspx in my project.

In Js files , for mandatory fields I am setting values like "Required"., which should be accessed from RESX

So based on the change in master page I should be able to change the above values.

 

 

I think, you can still use one of the samples from above. For example, you can define 

<script language="javascript" type="text/javascript">
var required_string = <%=GetGlobalResourceObject("Resource", "required") %>;
</script>

and then use required_string in jquery.

You might be also interesting in plug ins like http://keith-wood.name/localisation.html

Read more here http://www.novogeek.com/post/Client-side-localization-in-ASPNET-using-jQuery.aspx

Hope you will get your solution from the following reference

Leave a Reply