Label vs Literal


Label vs Literal:

Label:
<asp: Label id="lblMessage" runat="server" CssClass="anyclass" Text="My Label" />
will be rendered as:
<span id="ctl00_ContentPlaceHolder1_lblMessage" class="anyclass">My Label</span> //assuming you are using masterpage
Literal:
<asp:Literal id="ltrMessage" runat="server" Text="My Literal" />
will be rendered as:
My Literal
 In any case (with or without masterpage), extra <span> element with id is added to rendered HTML. You can see from the difference in rendering of Label and Literal control that Labels should be used only when any kind of styling needs to be applied to the Text rendered by Label. In my case, most of the time we are giving styles to the TD element and no extra styling required for Text inside TD element. In that case, you must use Literal control to minimize the amount of HTML rendered in browser.

Comments

Popular posts from this blog

Performance Optimization in Sitecore

𝗙𝗹𝘂𝗲𝗻𝘁𝗩𝗮𝗹𝗶𝗱𝗮𝘁𝗶𝗼𝗻 𝗶𝗻 𝗔𝗦𝗣.𝗡𝗘𝗧 𝗖𝗼𝗿𝗲 - 𝗖𝗹𝗲𝗮𝗻, 𝗙𝗹𝗲𝘅𝗶𝗯𝗹𝗲 𝗠𝗼𝗱𝗲𝗹 𝗩𝗮𝗹𝗶𝗱𝗮𝘁𝗶𝗼𝗻 𝗳𝗼𝗿 𝗠𝗼𝗱𝗲𝗿𝗻 .𝗡𝗘𝗧 𝗔𝗽𝗽𝘀

Azure Event Grid Sample code