LiteralControl in Markup!!!

I always had the question if I could add a LiteralControl via Markup code. Let's say something like that :

<div class="header">
    <asp:LiteralControl runat="server" ID="ltrHeader"></asp:LiteralControl>
</div>
<div class="sub-header">
    <asp:LiteralControl runat="server" ID="ltrSubHeader" Text="Some Text" ></asp:LiteralControl>
</div>

Well It IS possible and simple to be honest. Just Register the control at the top of the page like that :

<%@ Register Assembly="System.Web" Namespace="System.Web.UI" TagPrefix="asp" %>

You might have a warning that "Element 'LiteralControl' is not a known element." but it will compile just fine and you can set the Text programmatically!

Hope that helps anyone who wants to use a LiteralControl over Literal!

Enjoy!

5 Comments

  • Ummm.. For one you don't need to register that assembly in the page itself.. because its registered in the web config by default...

    Also <asp:Literal is the same dam thing as a Literal Control....

  • 1. You register that assemlby ONLY and I repeat ONLY if you want to use the LiteralControl. Also at web.config is the same namespace but another assembly registered.


    2. No. They are not the same. weblogs.asp.net/.../369294.aspx

  • LOL..

    Turn off viewstate on the literal control via the EnableViewState="false" and you have a LiteralControl without all the headaches.

  • I am with Bob here, ViewState of and go with a literal seems much easier. Hell if you are soo worried about viewstate why not just put a property on your view then:




    Even simpler.

  • Fantastic up-date on the infographic, Jesse! Pursuit is usually drastically treasured and present us SEMs some sort of fighting chance contrary to the wrong data throughout the online which gets was terrible in to Google places (formarly local business center).

Comments have been disabled for this content.