Access global resources in an asp.net control Access global resources in an asp.net control asp.net asp.net

Access global resources in an asp.net control


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


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") %>


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 %>");