Learning to use ASP. NET 2.0 for localization

Source: Internet
Author: User

For example, I have a Login page with two labels and two Textbox on it. The page is named Login. aspx, and the control is named lbl_UserName, lbl_Password, txt_UserName, and txt_Password.

First, you can create a new App_LocalResources folder on the website, and then create a new resource file named Login. aspx. resx
The name must be the same as that of the matched page. Create another resource file named Login. aspx. zh-Cn.resx.

Login. aspx. resx is the default, while Login. aspx. zh-Cn.resx is called when the browser's default language is set to Chinese.

Open the Login. aspx. resx file:
NAME value
LabelResource1.Text Username
LabelResource2.Text Password

Open the Login. aspx. zh-Cn.resx file:
NAME value:
LabelResource1.Text Username
LabelResource2.Text Password

Then, in our page code
Set
1 <asp: Label ID = "lbl_UserName" runat = "server"> </asp: Label>
2 <asp: Label ID = "lbl_Password" runat = "server"> </asp: Label> changed
1 <asp: Label ID = "lbl_UserName" runat = "server" Text = "<% $ Resources: LabelResource1.Text %>"> </asp: Label>
2 <asp: Label ID = "lbl_Password" runat = "server" Text = "<% $ Resources: LabelResource2.Text %>"> </asp: Label>
3
Finally, in the Page attribute of the Page, add the "Culture =" auto: zh-Cn "UICulture =" auto: zh-Cn ", which is set to Chinese by default.

After compilation, you can see the effect. When the default language of the browser is English, you can see that the two labels are displayed as Username and Password.
When the default language of the browser is Chinese, you can see that the two labels are displayed as the user name and password.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.