Access global resources in an asp.net control

被刻印的时光 ゝ 提交于 2019-12-21 06:59:21

问题


meta:resourcekey="WizardStep1Resource1"

This is what I use to access a App_LocalResources.

How do I access a resource in App_GlobalResources?

SOLUTION: Create a resource called Globalresource.resx in App_GlobalResources. In the file set a property called Test with the text Hello. Then it is called like Text='<%$ Resources:GlobalResource, Test%>'


回答1:


Text='<%$ Resources:Resource, WizardStep1Resource1 %>'

Text is the name of the property you want to set. Resource is the name of the global Resourcefile resp. ResourceClass and WizardStep1Resource1 is the name of the Resource Text.

See here: http://msdn.microsoft.com/en-us/magazine/cc163566.aspx




回答2:


You can only access a resource in App_GlobalResources explicitly, using the implicit wiring i.e. meta:resourcekey="WizardStep1Resource1" is applicable only for local resources

http://msdn.microsoft.com/en-us/library/ms227427.aspx

To access a resource in App_GlobalResources, use explicit localization like

   <%= (string)GetGlobalResourceObject("ResourcesClass", "WizardStep1Resource1") %>



回答3:


There are 2 ways to access a Global resources from C# code and from javascript functions. Below you can see both ways.

Imagine that you created a Global resource named WholeSite, inside you have a row named UnexpectedError.

txTitle is TextBox field.

C# Code:

txtTitle.Text = Resources.WholeSite.UnexpectedError; 

Javascript/.aspx:

alert("<%= Resources.WholeSite.UnexpectedError %>");


来源:https://stackoverflow.com/questions/7405605/access-global-resources-in-an-asp-net-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!