Jupaol
Jupaol

Reputation: 21365

Difference between Localize vs Literal

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

Upvotes: 4

Views: 2693

Answers (3)

DNR
DNR

Reputation: 3746

@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.

Upvotes: 5

keep fool
keep fool

Reputation: 101

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.

Upvotes: 0

Andrew Barber
Andrew Barber

Reputation: 40150

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.

Upvotes: 1

Related Questions