Learn to use ASP.net 2.0 localization

Source: Internet
Author: User
Tags resource
asp.net

For example, I have a landing page with two labels and two textbox, the page is named Login.aspx and the control is named Lbl_username,lbl_password,txt_username,txt_password.

You can start by creating a new App_LocalResources folder on your Web site, and then create a new resource file named Login.aspx.resx
The naming needs are the same as the matching page names. Then create another new resource file, named Login.aspx.zh-cn.resx

Login.aspx.resx This is the default, and Login.aspx.zh-cn.resx this is called when the browser default language is set to Chinese.

Open Login.aspx.resx File:
Name value
Labelresource1.text Username
Labelresource2.text Password

Open Login.aspx.zh-cn.resx File:
Labelresource1.text User Name
Labelresource2.text Password

And then, in our page code,
Put <asp:label id= "lbl_username" runat= "Server" ></asp:Label>
<asp:label id= "Lbl_password" runat= "Server" ></asp:Label>
Change to <asp:label id= "Lbl_username" runat= "Server" text= "<%$ Resources:LabelResource1.Text%>" ></asp: Label>
<asp:label id= "Lbl_password" runat= "Server" text= "<%$ Resources:LabelResource2.Text%>" ></asp:label >

Finally, in the page property of the pages, add culture= "AUTO:ZH-CN" uiculture= "AUTO:ZH-CN", which is set to Chinese by default.

When the browser default language is in English, you can see that two labels are displayed as username and password.
When the browser default language is Chinese, you can see that two labels appear as user names and passwords.



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.