views:

743

answers:

2

When I use the Visual Studio menu Tool -> Generate Local Resource, it changed aspx file by adding meta attributes to controls. But it doesnt do so for user controls that I have created.

For example, If I have used a control in the page

<myControl:SpecialLabelControl ID="myLabel" runat="server" Text="Localize Me!" />

I want "Localize Me!" to go in the resource file and a meta attribute added to the SpecialLabelControl.

How can I do this?

How does the tool create resource strings for built in controls automatically? Does it read an attribute of the property? How can I make the tool do the same to my control?

A: 

Add it manually into the resource file as:

myLabel.Text

Then change the control to:

<myControl:SpecialLabelControl ID="myLabel" runat="server" meta:resourceKey="LiteralIdentifyBody" />
Steven Robbins
Yes, thats what I am doing now. But how does the tool create resource strings fro built in controls automatically? Does it read an attribute of the property? How can I make the tool do the same to my control?
Puneet
Ah, sorry, I misunderstood your question, it might be using the DefaultProperty attribute.
Steven Robbins
+1  A: 

Firstly, make sure 'Text' is a publicly accessible property on your control.

Add [Localizable(true)] above the declaration, as shown in the example on this page

This will tell the IDE that this property is supposed to be picked up by resource files, and Tools -> Generate Local Resources will do the rest! EDIT - after further research I came across this article (and excerpt from a book). It seems that UserControls you created with publicly accessible properties can't be hit by the GLR tool :(

The ones I've worked on before were classes I created as '.cs' files, not user controls, I suppose.

Jeff