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

yuzhangqi發表於2010-09-16

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.

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.

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.

  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.

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/13651903/viewspace-1038461/,如需轉載,請註明出處,否則將追究法律責任。

相關文章