4

I was just reading about the difference between the Literal control and the Localize

I know this question was already asked here but the response proposed there does not work in my case.

According to MSDN:

The Localize control inherits from the Literal control and is identical to it in every way. The Localize control is used at design time to distinguish static text that can be localized from other static text.

My current understanding between the Localize and Literal controls is that the former renders a default value at design time in Visual Studio while the latter will render a calculated value instead, for example the content of a resource file.

I created a small page to prove this and I cannot find any difference this is why I have tried:

    <div><asp:Localize ID="Localize1" Text="<%$Resources: Resource, String1 %>" runat="server" >String1</asp:Localize></div>
    <div><asp:Literal ID="Literal1" Text="<%$Resources: Resource, String1 %>" runat="server" >String1</asp:Literal></div>
    <div><asp:Label ID="Label1" Text="<%$Resources: Resource, String1 %>" runat="server" >String1</asp:Label></div>

The above code renders as follows:

    <div>ploop</div>
    <div>ploop</div>
    <div><span id="Label1">ploop</span></div>

So far so good, but I was hoping to spot a difference in Visual Studio at design time but I didn't, this is the Visual Studio output

enter image description here

As an additional note, I know that when working with resources I could use implicit resources (when working with local resources), to use a default value at design time. Example:

    <asp:Label ID="Label1" runat="server" meta:resourcekey="Label1Resource1" 
        Text="Label"></asp:Label>

Using the above code I get the text Label rendered at design time in Visual Studio as expected.

So what's the difference between the Literal and the Localize controls?, What am I missing?

Note: I tested using a Website and a Web application

Community
  • 1
  • 1
Jupaol
  • 21,107
  • 8
  • 68
  • 100

3 Answers3

5

@Jupaol, not sure if you are clear on exactly what the <asp:Localize> control does, but it will convert the text into whatever the local language is. Take a look at When should I use a Localize control instead of a Literal? and hopefully that will make more sense.

Community
  • 1
  • 1
DNR
  • 3,706
  • 14
  • 56
  • 91
1

As you quoted, they are identical in every way.

The only difference is that one is a Localize. That's it. That would enable other classes to treat the Literal differently, if they wanted to. But again: they are identical.

It's essentially just a marker class.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
  • I haven't heard something like this, I mean it doesn't make sense to me to have a UI control as a mark. It makes sense when you have interfaces to mark your classes but UI controls?...can you provide an example? I cannot think in one practical use from the top of my head – Jupaol Aug 10 '12 at 01:36
  • Well, if Localize does not add any code, as MSDN says, the only possible answer is it is a marker class. 'Identical' is a pretty clear word, here. – Andrew Barber Aug 10 '12 at 01:39
0

http://msdn.microsoft.com/en-us/library/ms227668(v=vs.80).aspx

From the MSDN link it says "The Localize control is identical to the Literal Web server control and similar to the Label Web server control."

You can get more detail from the link.

keep fool
  • 101
  • 4