[Convert thyking xiao's blog] asp.net 2.0 for multiple languages (1)

Source: Internet
Author: User
1. Create an asp.net web Application

2. Shows the created Project.

3. Right-click the web Project name and add a global resource folder "app_GlobalResources", which is unique to asp.net 2.0.

4. Right-click the "app_GlobalResources" folder and add two resource files: language. resx (simplified resource file) and language. en-us.resx (resource file in English)

5. Open two resource files and add corresponding resource information, as shown in

6. Open the default. aspx file and enter the following code:
<Body>
<Form id = "form1" runat = "server">
<Center>
<Div style = "margin: 20px; padding: 10px; height: 200px; width: 200px; border: solid 1px # C0C0C0;
Text-align: center; ">
<Br/>
<A href = "? Curlanguage = zh-cn "> Chinese </a> & nbsp;
<A href = "? Curlanguage = en-us "> English </a>
<Br/>
<Br/>
Country: & nbsp; <asp: Literal ID = "ltlcountry" runat = "server"> </asp: Literal>
<Br/>
City: & nbsp; <asp: Literal ID = "ltlcity" runat = "server"> </asp: Literal>

<Br/>
<Br/>
Country 2: & nbsp; <asp: Literal ID = "ltlcountry2" runat = "server"> </asp: Literal>
<Br/>
City 2: & nbsp; <asp: Literal ID = "ltlcity2" runat = "server"> </asp: Literal>
</Div>
</Center>
</Form>
</Body>

Preview as shown in:

7. Open the Default. aspx. cs file and enter the following code:

// This code is very important
Protected override void InitializeCulture ()
{
String culture = Request. QueryString ["curlanguage"];
If (! String. IsNullOrEmpty (culture ))
{
System. Threading. Thread. CurrentThread. CurrentUICulture = new System. Globalization. CultureInfo (culture );
System. Threading. Thread. CurrentThread. CurrentCulture = System. Globalization. CultureInfo. CreateSpecificCulture (culture );
}
}

Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
Ltlcountry. Text = Resources. language. country. ToString ();
Ltlcity. Text = Resources. language. city. ToString ();

Ltlcountry2.Text = (string) GetGlobalResourceObject ("language", "country ");
Ltlcity2.Text = (string) GetGlobalResourceObject ("language", "city ");

}
}

8. For the entire project under build, press F5 to browse: click the "Chinese" and "English" links in to view the results we want.

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.