i have a component project with controls for our site – that must now be localization-able. setting up the localization for the rest of the site was not a problem (we dropped .resx files into the App_GlobalResources directory; everything was hunky-dory), but i’m having a difficult time finding information on how to access resources locally within the component project.
- the
App_Local[/Global]Resourcesfolders don’t want work – i can’t “Add ASP.NET Folder” the way i can from the main project. - when i generate it myself and drop .resx files into it, i can’t figure out how to access them like i did in the site.
some abbreviated control code, contained entirely within ThisWidget.cs in the component project:
namespace site.shop {
[ToolboxData("<{0}:ThisWidget runat=server></{0}:ThisWidget>")]
public class ThisWidget : WebControl {
protected override void CreateChildControls() {
if (ChildControlsCreated) { return; }
this.Controls.Clear();
Label head = new Label();
head.CssClass = "header";
// fails: ThisWidget does not exist in namespace
head.Text = System.Resources.ThisWidget.Label_head;
// fails: can't find GetLocalResourceObject
head.Text = new System.Web.UI.TemplateControl.GetLocalResourceObject("Label_head");
// fails: can't find linked or embedded resources
System.Resources.ResourceManager rm = new ResourceManager();
head.Text = Convert.ToString(rm.GetObject("Label_head"));
this.Controls.Add(head);
}
}
}
and several variations with/out new, System.Web.UI.TemplateControl, etc…
i’d prefer not to have to compile this as a satellite assembly and then pull it back in (which seemed to be the other option), since the component project (a) has a number of related controls, and (b) is sort of a satellite dependency already, right? my hope was that i could drop the .resx files in, compile the .DLL, then the rest of the project can work.
[edit]
i feel like i’m getting closer to the answer, but i’m just not quite there yet…
any ideas? what am i missing?
thanks!
oh, i was getting close – i popped open the
ThisWidget.Designer.csand found the correct parameters to callResourceManager()with:seems to work like a charm. i also realized that since it is ignoring the specialness of
App_LocalResources, i could put it anywhere, so i made a/Resources/Resx/directory and put the.resxfiles for each of the components’ controls in with it. to update the call, this: