Literal Controls

Literal Controls

ASP.NET Literal Control

  • Reserves a location on a Web page to display raw text
  • Passes content directly to browsers except when the Mode property is set to encode content
  • Similar to a Label control but without any style support for displayed text
  • Styles can only be applied by including markup in the Text property along with the content
  • Implemented in Sitecore solutions by placing on a Sublayout

ASCX Markup

<div style="font-weight: bold; width: 100%; clear: both">     <asp:Label ID="Label1" runat="server" /> </div> <div style="font-size: x-small; width: 100%; clear: both">     <asp:Label ID="Label2" runat="server" />     <asp:Literal ID="Literal1" runat="server" />     <asp:Literal ID="Literal2" runat="server" /> </div>


  • ASP.NET controls render themselves as HTML when the page is finished rendering
  • ASP.NET web controls provide more functionality than HTML server controls

Literal Controls C# User Control Code

 if (!IsPostBack)
                Sitecore.Data.Items.Item item = Sitecore.Context.Item;
                if (item == null) return;

                Label1.Text = "C# User Control Real-time Output";
                string displayName = Sitecore.StringUtil.GetString(item.DisplayName, item.Name);
                //using &#58; for colon and &#160; for space
                Label2.Text = ("<p>Item&#58;&#160;" + "<b>" + displayName + "</b></p>");
                Literal1.Text = "Page Title&#58;&#160" + item["Title"] + "<br/>";
                Literal2.Text = "Page Theme&#58;&#160" + item["Theme"];