Udostępnij za pośrednictwem


How to: Use Resources to Set Property Values in Web Server Controls

In an ASP.NET page, you can use the following methods to read values from resource files:

  • Implicit localization   ASP.NET fills property values from a local resource file based on matching keys to properties. By using a tool in Visual Web Developer, you can automatically mark all of the controls on a page for implicit localization.

  • Explicit localization   Create an expression that reads a specific resource from a local or global resource file. You should create expressions for every control property that you want to set by using a resource.

You can also read values from resource files programmatically. For more information, see How to: Retrieve Resource Values Programmatically. For more information about implicit and explicit localization, see ASP.NET Web Page Resources Overview and How to: Use Resources to Set Property Values in Web Server Controls.

To use implicit localization

  1. Open the page for which you want to create resource files.

  2. Switch to Design View.

  3. In the Tools menu, click Generate Local Resource.

    Visual Web Developer creates the App_LocalResources folder if it does not already exist. Visual Web Developer then creates the base resource file for the current page, which includes a key/name pair for every localizable control of every ASP.NET Web server control on the page. Finally, Visual Web Developer adds a meta attribute to each ASP.NET Web server control to configure the control to use implicit localization.

    Note

    You can also add the meta attribute manually in Source view. For details, see How to: Use Resources to Set Property Values in Web Server Controls.

To use explicit localization with resource expressions

  1. In Design view, select the control for which you want to use resource expressions.

  2. In the Data category of the Properties window, click (Expressions) andthen click the ellipsis button.

  3. In the Expressions dialog box, under Bindable Properties, select the property that you want to set by using a resource.

  4. In the Expression type list, click Resources.

  5. If you are working with global resources, then type the class name for the resource file that you want to use in the ClassKey box.

    Note

    The class name is based on the name of the .resx file. A resource file named WebResources.resx uses the class name WebResources. All resource files in all languages use the same class name. If you want to get a resource from the local resource file that is associated with the current page, this value is optional.

  6. In the ResourceKey box, type the name of the resource that you want to use. If you are using the local resource file for the current page, you can click the drop-down arrow to see a list of resources that are available in the file.

  7. Repeat steps 3 through 6 for each property that you want to set in the current control and then click OK.

  8. Repeat steps 1 through 8 for each control for which you want to use resources.

See Also

Tasks

Walkthrough: Using Resources for Localization with ASP.NET

How to: Retrieve Resource Values Programmatically

Concepts

ASP.NET Web Page Resources Overview