Localize Web Server Control
in ASP.NET environment,The Localize Web server control enables you to display localized text in a specific area on your ASP.NET Web page. This article help you to understand about how to work with the Localize Web server control.
Localize Control Vs Literal Control
The Localize control is identical to the Literal Web server control and similar to the Label 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 Text property, which is inherited from the Literal control.
Encoding Content in the Localize Control
The Localize control contains the Mode property, which specifies how the control handles markup that you add to it. You can set the Mode property to these values:
- Transform - Any markup you add to the control is transformed to accommodate the protocol of the requesting browser.
- PassThrough -Any markup you add to the control is rendered as-is to the browser.
- Encode - Any markup you add to the control is encoded using the HtmlEncode method, which converts HTML encoding into its text representation.
using Localize Control with Resource file
By using explicit or implicit of the Localize Control,You can display text in Localize control. 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 Arabic version of your resource file would be named LocalizeText.ar.resx.
To add a Localize control to a page
- Type an <asp:Localize> element in the page.
- Optionally, set the Mode property to Transform, PassThrough, or Encode. The Mode property specifies how the control handles any markup that is added to it.
- You must set the Id and runat property of the Literal Web Control.
the following code snippets demonstrates a Literal control
<body>
<form id="Form2" runat="server">
<h1><asp:Localize id="Headline" runat=server
mode="PassThrough"/></h1>
</form>
</body>
To add Control's Text programmatically
the following code snippets demonstrates this
in .aspx.cs page,
protected void Page_Load(object sender, EventArgs e)
{
Localize1.Text = "changed.";
if (radioEncode.Checked == true)
{
Localize1.Mode = LiteralMode.Encode;
}
if(radioPassthrough.Checked == true)
{
Localize1.Mode = LiteralMode.PassThrough;
}
}
in .aspx page,
<html>
<head id="Head1" runat="server"></head>
<body>
<form id="form2" runat="server">
<div>
<br />
<asp:RadioButton
ID="radioEncode"
runat="server"
GroupName="LiteralMode"
Checked="True"
Text="Encode"
AutoPostBack="True" />
<br />
<asp:RadioButton
ID="radioPassthrough"
runat="server"
GroupName="LiteralMode"
Text="PassThrough"
AutoPostBack="True" />
<br />
<br />
<asp:Literal ID="Localize1" runat="server"></asp:Literal> </div>
</form>
</body>
</html>
458bf69a-b65c-46a4-832d-7c943b6f9a5f|0|.0