Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the Resource String in javascript

How can I set the resource string in javascript?

I have a resource file called, for example,

myResourceFile.resx

in my code and using the literal control I can use:

lblName.Text = Resources.myResourceFile.ajaxRetrievingInformation;

<asp:Literal id="lit" runat="server" 
             Text="<%$ Resources:myResourceFile, ajaxRetrievingInformation%>" />

but if I try this in javascript, like:

<asp:Button ID="btnImportCompaniesAndEmployees" 
            runat="server" 
            CssClass="myButtonCssClass"
            OnClick="btnImportCompaniesAndEmployees_Click"
            OnClientClick="strLoadingText='<%$ Resources:myResourceFile, ajaxRetrievingInformation%>';return true;"
            ...
/>

or

<script type="text/javascript">
    var strLoadingText = '<%$ Resources:myResourceFile, ajaxRetrievingInformation%>';
</script>

I get errors...

Does anyone know how to manage this? Something like:

var strLoadingText = Resources.GetString(myResourceFile, ajaxRetrievingInformation);

Thanks

like image 324
balexandre Avatar asked Mar 10 '09 14:03

balexandre


1 Answers

You should be able to use:

<script type="text/javascript">
    var strLoadingText = "<%= Resources.myResourceFile.ajaxRetrievingInformation %>";
</script>
like image 120
Joel Avatar answered Sep 22 '22 17:09

Joel