Localize Web Server Control Overview
You can add aWeb server control to your ASP.NET Web page when you want to display localized text in a specific area on your page.
Comparing the Localize Control to the Literal Control
The Localize control is identical to theWeb server control and similar to the Web server control. While the Label control allows you to apply a style to the displayed text, the Localize control does not. You can programmatically control the text that is displayed in the Localize control by setting the property, which is inherited from the Literal control.
Encoding Content in the Literal Control
The Localize control supports theproperty, which specifies how the control handles markup that you add to it. You can set the Mode property to the following values:
Any markup that you add to the control is transformed to accommodate the protocol of the requesting browser. This setting is useful if you are rendering content to mobile devices that use a protocol other than HTML.
Any markup that you add to the control is rendered as-is to the browser.
Any markup that you add to the control is encoded using the method, which converts HTML encoding into its text representation. For example, a
<b>tag is rendered as
<b>. Encoding is useful when you want the browser to display markup rather than interpret it. Encoding is also useful for security, to help prevent malicious markup from being executed in the browser, and is recommended if you are displaying strings from an untrusted source. For more information, see .
Localizing Text Using Resource Strings
You can create localized strings to display in the Text property of the Localize control by using an explicit or implicit expression as the value of the property. Expressions are evaluated by using strings that are declared in resource (.resx) files.
Create your .resx files in folders called App_GlobalResources and App_LocalResources in the root of your application. If you need to localize strings for multiple languages, you can create additional .resx files with locale information included in the file name. For example, the French version of your resource file would be named ExampleLocalizedStrings.fr.resx.
For more information about expressions, see. For information about resource files, see . For a code example that uses regular expressions in the Localize control, see .