views:

227

answers:

3

Should I use the resource file directly in the aspx page like

<asp:Literal ID="userManagementSave" Text="<%$ Resources: save_lbl %>" runat="server" />

or creating a sub in the code like

private sub setLang()
   userManagementSave.text = GetLocalResourceObject("save_lbl")
end sub
+1  A: 

I favor referencing the text inline, since it is easier to update by not being in the code behind.

Since the only functionality you are after is content output, you'll be fine doing it inline. If you were doing anything more complicated, then a method in the code behind would be better.

ern
+1  A: 

Ern's answer is good. Typically, when you're maintaining code, if you have to fix something on the page, you're going to start looking in the aspx file first, just find the name of the control. If that code is inline, you'll find it immediately and won't have to jump around to find it.

If you find yourself writing any more code in the aspx than this property assignment, move at least to the code-behind, because code is harder to debug and read in the aspx.

Mark A Johnson
A: 

I'm currently using VSTS 2008 but I seem to remember this capability being available in VS2005 also ...

Basically use the inbuilt support for generating Local Resources

  • Write the Html for the aspx
  • Set all properties with a sensible string (e.g. lblName.Text = "Name")
  • Make sure that the aspx page is open in the designer
  • Tools --> Generate Local Resource
  • A resource file is automatically generated in a sub directory called App_LocalResources. Values of resources are set to the text provided in Html

N.B. Html has been updated to include meta tags

This is a useful technique because it generates resources for all the properties of controls that are required to be provided to make a page fully multi-language/all strings stored in resources i.e. alt on Image - always forget that one! You don't have to provide text for all resource keys if you don't want to.