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 ();