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.