Label Controls

Label Controls

ASP.NET Label Control

  • Displays text on a Web page
  • Similar to a Literal control but supports styles for formatting displayed text
  • 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">     <p>         <asp:Label ID="Label2" runat="server" />         <asp:Label ID="Label3" runat="server" Style="font-style: italic; color: Maroon" /></p> </div>

ASCX Code Behind

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

            Label1.Text = "C# User Control 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>");
            Label3.Text = "Menu Title&#58;&#160;" + item["Menu Title"];;