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.
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.
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.
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.
Use HttpContext.GetGlobalResourceObject instead:
<asp:Label text='<%= GetGlobalResourceObject("Messages", "ThankYouLabel") %>'
id="label1"
runat="server" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With