Sunday, October 19, 2008 1:25 PM
djsolid
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!
Filed under: Web Development, ASP.NET, .NET, LiteralControl