Multi-language support for ASP. NET websites

Source: Internet
Author: User

First, you need to create an ASP. NET Web Application. Then Right-click the project file Add-> Add ASP. NET Folder-> App-GlobalResources.

After creating a resource folder, add a resx file to the folder. Here, I add a LocalText. resx file.

 

Set the Value of Name and Value, as shown in.

Save and copy LocalText. resx, paste it to the App_GlobalResources folder, and rename it LocalText. zh-CN.resx.

 

Set the Value of Name and Value.

On the page, we can use

<Asp: Button ID = "submit" runat = "server" Text = '<% $ Resources: LocalText, ButtonText %>'/>

Then we need to define a public class BasePage. The BasePage inherits from System. Web. UI. Page, and the Page inherits from BasePage.

In BasePage, We need to override the InitializeCulture method. The detailed code is as follows:

 

The InitializeCulture method is executed when all pages are loaded.

Take the button used in the new Default page as an example. When a user accesses the Default page in a browser with lang = zh-CN, the button is displayed and submitted. When you access the Default page with lang = en-US, the button displays the submit.

 

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.