Marco Bellinaso's Blog

 Tuesday, May 09, 2006


You can create page-level resources by creating resource files just as you do for global resources, but placing them under a folder named App_LocalResources (as opposed to App_GlobalResources used for global resources) located at the same level of the page to localize. For example, if the page is in the root folder, then you’ll create the App_LocalResources under the root folder, but if the page is under /Test, then you’ll create a /Test/App_LocalResources folder. This means you can have multiple App_LocalResources folders, whereas you can only have one App_GlobalResources folder for the whole site. The name of the resource filename is also fundamental, as it must be named after the page or control file for which it contains the localized resources, plus the part with the culture name: For example, a culture-neutral resource file for Localization.aspx would be named Localization.aspx.resx, whereas it would be named Localization.aspx.it-IT.resx for the Italian resources. In Figure 11-5, you can see the organization of files in the Solution Explorer, and the resource file being edited in the grid editor.

 

Figure 11-5

You can still use the Expressions dialog shown in Figure 11-4 to bind a control’s property to an expression pointing to a localized resource: When you point to a page-specific resource you just leave the ClassKey textbox empty. The code below shows the generated expression:

<asp:Label ID="lblCopyright" runat="server"

   Text="<%$ Resources:CopyrightMessage %>" / >

It differs from the expression shown in the previous section, as it doesn’t include the class name; it just specifies the resource key. If you want to access local resources programmatically, you use the page’s GetLocalResourceObject method, which takes the resource key name and returns an Object that you must cast to string or to the proper destination type (such as Bitmap if you stored an image):

string copyrightMsg = (string)this.GetLocalResourceObject("CopyrightMessage");

Even with localization expressions and local resources, localizing full pages will be a slow task if you need to create the expressions for dozens of controls, and things get worse if you need to localize multiple properties for the same control, such as Text, ToolTip, ImageUrl, NavigateUrl, and so on, which is often the case. To speed things up, Visual Studio offers the Tools @@> Generate Local Resource command, which generates a local resource file for the current page, and creates entries for all localizable properties of all controls on the page, following the ControlName.PropertyName naming convention for the names of the resources. Resource items are also automatically set with the value extracted from the page’s markup; if a property is not used in the control’s declaration, a resource item for it is generated anyway and left empty.

Localizable properties are those that are decorated with a [Localizable(true)] attribute, which you can add to the properties of your custom controls. However, even when you add it to properties of user controls, resources for those properties will not be automatically generated by the Generate Local Resource command. You can create the local resources for those properties yourself, and write the localization expressions to make the association: Everything will work perfectly at runtime, so this is only a design-time limitation. In addition, you’ll have to write the localization expressions manually, because the (Expressions) item is not available from the Properties window when a user control is selected.

Figure 11-6 shows the resource editor for the Localization.aspx.resx local resource file after executing this Generate Local Resource command on the test page.

Figure 11-6

Besides the automatic generation of the resource file (or the addition of the resource items, if a resource file for that page was already present in the proper folder), what’s even more interesting is that each control’s declaration is modified as follows (note the code in bold):

<asp:Label ID="lblTitle" runat="server" Font-Size="X-Large" ForeColor="#C00000"

   meta:resourcekey="lblTitleResource1" Text="Localization Demo"

   Text="This page provides a nice demo of new ASP.NET 2.0 localization features"

/>

A meta:resourcekey attribute is added to the declaration, and is set to the prefix used in the local resource file to identify all localized properties of that control, such as lblTitleResource1.Text and lblTitleResource1.ToolTip. These are called implicit localization expressions (expressions used earlier are considered explicit). At runtime, the framework parses all resources and applies them to the properties of the corresponding controls, making the mapping of the first part of the key with the value of meta:resourcename. This means that the control’s declaration is decorated with just a single new attribute, but may make multiple properties localizable. Later, if you want to localize a property that you didn’t take into account originally, you just need to go to the resource editor and add an item following the naming schema described above, or edit its value if it already exists.

Note that the controls retain their original property declarations after running the Generate Local Resource command. These declarations are no longer necessary, though, as the property’s value will be replaced at runtime with the values saved in the resource file; therefore, you can completely remove the definition of the Text, ToolTip, and the other localized properties from the .aspx files to avoid confusion.

This behavior works with the page’s title as well, originally defined in the @Page directive, which is modified as follows:

<%@ Page Language="C#" meta:resourcekey="PageResource1" …other attributes… %>


 NOTE: This excerpt was taken from the book "ASP.NET 2.0 Website Programming". Click here to find more about it, and download the complete source code of the sample project.

3/6/2008 5:29:41 PM (GMT Standard Time, UTC+00:00)
Cheapest Us Ultram
3/6/2008 5:41:36 PM (GMT Standard Time, UTC+00:00)
Cheap wellbutrin usage
3/6/2008 5:44:51 PM (GMT Standard Time, UTC+00:00)
cheapest carisoprodol sample
4/26/2008 1:02:59 AM (GMT Daylight Time, UTC+01:00)
I'm agree with you.
5/30/2008 12:09:11 AM (GMT Daylight Time, UTC+01:00)
Yes. Im agree.
6/14/2008 9:43:23 AM (GMT Daylight Time, UTC+01:00)
Yes. Im agree.
7/10/2009 1:30:13 AM (GMT Daylight Time, UTC+01:00)
I am agree with you too.
8/9/2009 3:49:41 PM (GMT Daylight Time, UTC+01:00)
Sell authentic [url=http://www.hotstyleugg.com/boots-ugg-c-47.html]boots ugg[/url], [url=http://www.hotstyleugg.com/]Uggs[/url] ,[url=http://www.hotstyleugg.com/]womens ugg[/url],[url=http://www.hotstyleugg.com/]Ugg Classic boots[/url],[url=http://www.hotstyleugg.com/]ugg womens boots[/url],they are high quality,cheap [url=http://www.hotstyleugg.com/]Classic ugg tall[/url] ship,[url=http://www.hotstyleugg.com/]womens ugg[/url] for sale, [url=http://www.hotstyleugg.com/]nightfall ugg boots[/url] sale. Our service is customer first, quality assurance and the credibility of the first.Free Shipping sale [url=http://www.hotstyleugg.com/]Classic Cardy Ugg[/url], [url=http://www.hotstyleugg.com/]Classic UGG short[/url], quality assurance and the credibility of the first.Free Shipping sale [url=http://www.hotstyleugg.com/]Uggs Classic Mini[/url], [url=http://www.hotstyleugg.com/]Ugg boots Classic[/url], [url=http://www.hotstyleugg.com/]ultra tall uggs[/url]. Our customers also like buy [url=http://www.hotstyleugg.com/]ugg classic[/url],[url=http://www.hotstyleugg.com/]ugg short boots[/url],[url=http://www.hotstyleugg.com/]ugg boots classic[/url],[url=http://www.hotstyleugg.com/]ugg tall boots[/url].[url=http://www.hotstyleugg.com/]ugg crochet boots[/url].we are your sincere retailer and wholesaler.I believe you will admit with us,after you do business with us,thank you!
[url=http://www.hotstyleugg.com/]Boots Ugg[/url]
[url=http://www.hotstyleugg.com/]Uggs[/url]
[url=http://www.hotstyleugg.com/]ugg womens boots[/url]
[url=http://www.hotstyleugg.com/]Ugg Classic boots[/url]
[url=http://www.hotstyleugg.com/]womens ugg[/url]
[url=http://www.hotstyleugg.com/]Classic ugg tall[/url]

[url=http://www.hotstyleugg.com/]Classic Cardy Ugg[/url]
[url=http://www.hotstyleugg.com/]nightfall ugg boots[/url]
[url=http://www.hotstyleugg.com/]Classic UGG short[/url]
[url=http://www.hotstyleugg.com/]Uggs Classic Mini[/url]
[url=http://www.hotstyleugg.com/]uggs crochet[/url]
[url=http://www.hotstyleugg.com/]ugg classic[/url]
[url=http://www.hotstyleugg.com/]ugg short boots[/url]>

[url=http://www.hotstyleugg.com/]ugg mini boots[/url]
[url=http://www.hotstyleugg.com/]ugg tall boots[/url]
[url=http://www.hotstyleugg.com/]ugg crochet boots[/url]
[url=http://www.hotstyleugg.com/]ugg classic cardy[/url]
[url=http://www.hotstyleugg.com/]ugg crochet tall[/url]
[url=http://www.hotstyleugg.com/]ugg sandals[/url]
[url=http://www.hotstyleugg.com/]ultra tall uggs[/url]
[url=http://www.hotstyleugg.com/]womens ugg shoes[/url]
Hello friends,100% genuine[url=http://www.hotstyleugg.com]Boots Ugg[/url], [url=http://www.hotstyleugg.com/]Uggs[/url] sale,high quality,packed with orginal boxes and tags also retro cards/code number.The detail sell products are [url=http://www.hotstyleugg.com]Ugg Classic boots[/url],[url=http://www.hotstyleugg.com]ugg womens boots[/url],[url=http://www.hotstyleugg.com]Classic ugg tall[/url],[url=http://www.hotstyleugg.com]womens ugg[/url],[url=http://www.hotstyleugg.com]nightfall ugg boots[/url],All our UGG products [url=http://www.hotstyleugg.com/]Classic Cardy Ugg[/url], [url=http://www.hotstyleugg.com/]nightfall ugg boots[/url],[url=http://www.hotstyleugg.com/]Classic UGG short[/url]are Grade A quality, the style is fashion and popular! Welcome to buy them,we are your sincere retailer and wholesaler.I believe you will admit,after you do business with us,thank you!
9/25/2009 5:37:21 PM (GMT Daylight Time, UTC+01:00)
Oh god, too late. we had enough hard time in this.GlobalResources.
11/30/2009 5:55:43 AM (GMT Standard Time, UTC+00:00)
This blog contains really good stuff.Thanks for sharing this interesting blog.
12/8/2009 5:09:56 PM (GMT Standard Time, UTC+00:00)
Again, another good post!
12/21/2009 11:22:20 AM (GMT Standard Time, UTC+00:00)
This is the awesome post. This is really knowledgeable post to all the students.
1/7/2010 2:23:28 PM (GMT Standard Time, UTC+00:00)
Your blog provides us a very great information. Its really very helpful to me to find result on search engine. Hope to hear more good information related to searching from your side.
1/18/2010 2:44:34 AM (GMT Standard Time, UTC+00:00)
Do you have a pair of shoes that for doing exercising??why not think of the comfortable MBT shoes???
3/14/2010 7:27:45 AM (GMT Standard Time, UTC+00:00)
We all know that fashion is something that is extremely difficult to keep up with.except .lovinwholesale.comWhether you are trying to look fashionable or you are attempting to keep up with the latest and greatest fashion,it is very hard.titleLaguna Beach" www.lovinwholesale.comLaguna-Beach.html" alt="Laguna Beach">Laguna Beach
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

 
Get RSS/Atom Feed
RSS 2.0 | Atom 1.0
Search in the blog
Archive
<March 2010>
SunMonTueWedThuFriSat
28123456
78910111213
14151617181920
21222324252627
28293031123
45678910
Categories

Powered by: newtelligence dasBlog 1.8.5223.1