Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between these two ways of localizing a string in an aspx/ascx file?

When I started localizing a website the first time, I just did the localization like this:

<%= Resources.ResourceFile.ResourceName %>

and it seems to work perfectly fine. However, the ReSharper 5.0 Beta does it like this:

<asp:Localize Text="<%$ Resources: ResourceFile, ResourceName %>" runat="server">
  Value
</asp:Localize>

Does it matter which way it gets done?

Also, why does ReSharper keep the original text inside the localize control? I thought it was there in case the Value inside the Resource file was empty, it could show the "default" text. This does not appear to be the case. Is it safe to remove it and just self close the localize control?

like image 324
Brandon Avatar asked May 21 '10 14:05

Brandon


1 Answers

well, you can't use the <%= %> server tag on a asp server control.

so

<asp:Localize Text="<%= Resources.ResourceFile.ResourceName %>" runat="server">
  Value
</asp:Localize>

will result in a compilation error. Unfortunately you cannot pass dynamic data to server control properties unless it is databound where you can apply the <%# %> server tag, for example:

<asp:Repeater runat="server">
...
  <asp:Localize Text="<%# Resources.ResourceFile.ResourceName %>" runat="server">
   Value
  </asp:Localize>
...
</asp:Repeater>

You can always move this to the codebehind but that sucks.

the <%$ %> 'thing' works however if you go by it prepare to enter maintenance hell (unless of course we are talking about a 3 page application...)

Personally i use the <%= %> and i never use re-sharper to globalize/localize my apps. Also, i've never used the <asp:Localize /> server control and i've had no problems...

like image 111
Jaguar Avatar answered Sep 28 '22 19:09

Jaguar