简体   繁体   English

访问asp.net控件中的全局资源

[英]Access global resources in an asp.net control

meta:resourcekey="WizardStep1Resource1"

This is what I use to access a App_LocalResources . 这是我用来访问App_LocalResources

How do I access a resource in App_GlobalResources ? 如何访问App_GlobalResources的资源?

SOLUTION: Create a resource called Globalresource.resx in App_GlobalResources . 解决方案:在App_GlobalResources创建名为Globalresource.resx的资源。 In the file set a property called Test with the text Hello. 在文件中设置一个名为Test的属性,文本为Hello。 Then it is called like Text='<%$ Resources:GlobalResource, Test%>' 然后它被称为Text='<%$ Resources:GlobalResource, Test%>'

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

Text is the name of the property you want to set. Text是要设置的属性的名称。 Resource is the name of the global Resourcefile resp. Resource是全局Resourcefile的名称。 ResourceClass and WizardStep1Resource1 is the name of the Resource Text. ResourceClass和WizardStep1Resource1是资源文本的名称。

See here: http://msdn.microsoft.com/en-us/magazine/cc163566.aspx 请参见此处: http//msdn.microsoft.com/en-us/magazine/cc163566.aspx

You can only access a resource in App_GlobalResources explicitly, using the implicit wiring ie meta:resourcekey="WizardStep1Resource1" is applicable only for local resources 您只能使用隐式连接显式访问App_GlobalResources中的资源,即meta:resourcekey="WizardStep1Resource1"仅适用于本地资源

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

To access a resource in App_GlobalResources, use explicit localization like 要访问App_GlobalResources中的资源,请使用显式本地化

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

There are 2 ways to access a Global resources from C# code and from javascript functions. 有两种方法可以从C#代码和javascript函数访问全局资源。 Below you can see both ways. 下面你可以看到两种方式。

Imagine that you created a Global resource named WholeSite, inside you have a row named UnexpectedError. 想象一下,您创建了一个名为WholeSite的全局资源,其中有一行名为UnexpectedError。

txTitle is TextBox field. txTitle是TextBox字段。

C# Code : C#代码

txtTitle.Text = Resources.WholeSite.UnexpectedError; 

Javascript/.aspx : Javascript / .aspx

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM