Use ASP.NET Resource strings from within javascript files

后端 未结 9 1709
迷失自我
迷失自我 2020-12-13 01:02

How would one get resx resource strings into javascript code stored in a .js file?

If your javascript is in a script block in the markup, you can use this syntax:

9条回答
  •  死守一世寂寞
    2020-12-13 01:11

    whereas "Common" is the name of the resource file and Msg1 is the fieldname. This also works for culture changes.

                Partial Javascript...:
                messages: 
                {
                    <%=txtRequiredField.UniqueID %>:{                       
                        required: "<%=Resources.Common.Msg1 %>",
                        maxlength: "Only 50 character allowed in required field."
                    }
                }
    

提交回复
热议问题