Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display value of Resource without Label or Literal control

How do I display the value of a resource without a ASP.NET control, i.e. I want to avoid this:

<asp:Label text="<%$ Resources: Messages, ThankYouLabel %>" id="label1" runat="server" />

Instead I would prefer to do just this in my .aspx pages:

<%$ Resources: Messages, ThankYouLabel %>

... but I can’t, a parser error is thrown:

Literal expressions like '<%$ Resources: Messages, ThankYouLabel %>' are not allowed.
Use <asp:Literal runat="server" Text="<%$ Resources: Messages, ThankYouLabel %>" /> instead.
like image 417
Jakob Gade Avatar asked Mar 08 '11 07:03

Jakob Gade


People also ask

What is the difference between label and Literal control in asp net?

Label control can be styled i.e. its Font, Color, Font Size, etc. can be easily changed but Literal control cannot be styled as it does not use any HTML tag. Label control enables to display static text on the web page. while Literal control is used most frequently when adding content dynamically to the page.

What do you mean by Literal control?

The Literal control is used to display text; that is, it renders static text on a Web page without adding additional HTML tags. It passes content directly to the client browser unless you use the Mode property to encode the content.

What are the properties that Literal control does not support?

You cannot apply a style to a literal control. Unlike Label control, there is no property like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. for Literal control. That makes it more powerful, you can even put a pure HTML contents into it.


1 Answers

Use HttpContext.GetGlobalResourceObject instead:

<asp:Label text='<%= GetGlobalResourceObject("Messages", "ThankYouLabel") %>' 
     id="label1" 
     runat="server" />
like image 106
Oleks Avatar answered Sep 21 '22 20:09

Oleks