Asp.net 2.0 Language Pack globalization

Source: Internet
Author: User

Create a test site and add a page test. aspx. Pull a label control on the page and name it labtest.
Add two special folders: app_globalresources app_localresources
Right-click app_localresources and add a new file named test. aspx. resx to open test. aspx. resx.
Add a new record name: labtest value: Test
Copy the test. aspx. resx file. And name it test. aspx. En. resx (English EN). Change labeltest to test.
Next, in <% @ page Language = "C #" autoeventwireup = "true" codefile = "test. aspx. CS "Culture =" Auto: ZH-CN "uiculture =" Auto: ZH-CN "inherits =" test "%>
Add the culture and uiculture (test shows that the culture does not work and can be deleted)

Open the labtest property box. Locate dataexpression expression type, select resource, and select labtest for resourcekey.
View this page. We can see two test words
Next. Internet option language adds a new language en and puts it first .. Refresh the page and you will see Test
Note: The name of the resource file in the app_localresources folder. "language code". resx, and a default non-language code is required.

Let's continue to try app_globalresources (Global Resource) to create a resource. ascx and add labtest2 value: Test 2.
Copy a resource. En. ascx with the value Test2.
In test. aspx, pull a label, select data expression, continue to select resource, and put Resource (the name just obtained) into classkey. Then you can select
Resourcekey is labtest2

Test. You can see what you want.

How to control the language on your own. We only need to override initializeculture () and set system. Threading. thread. currentthread. currentuiculture = new system. Globalization. cultureinfo ("name ");

Protected override void initializeculture ()
{
System. Threading. thread. currentthread. currentuiculture = new system. Globalization. cultureinfo ("name ");
// Base. initializeculture ();
}

You can.

At this time, you may ask what we need to dynamically prompt what to bind.
We found it very easy.
You can use
This. Title = resources. Resource. labtest2; in this way, you can obtain the resource (also the name of your resource)
 

This. Title = httpcontext. getlocalresourceobject ("~ /Activitylist. aspx "," title "). tostring ();

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.