posted 7/21/2010 by mohit kumar
In this blog I will explain Literal control in ASP.NET.
The Literal control used to display static text on a web page. Literal control is not rendered as a <span> tag like label control. The Literal control doesn’t inherit from WebControl and we can’t apply style to its content because it doesn’t have a style property. There is a Mode property of Literal control.
There are three modes available in literal control –
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LiteralMode.aspx.cs" Inherits="LiteralMode" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:Literal ID="Literal1" runat="server" Mode="Encode" ></asp:Literal><br /> <asp:Literal ID="Literal2" runat="server" Mode="PassThrough"></asp:Literal><br /> <asp:Literal ID="Literal3" runat="server" Mode="Transform"></asp:Literal> </div> </form> </body> </html>
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class LiteralMode : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { Literal1.Text= "My name is <b>Mohit</b>.<script>alert('Hello World');</script>"; Literal2.Text = "My name is <b>Mohit</b>.<script>alert('Hello World');</script>"; Literal3.Text = "My name is <b>Mohit</b>.<script>alert('Hello World');</script>"; } }
Nice input! :)
Thanks all for your appreciating comments.
nice post :)
Good one.
nice post mohit!! keep it up.
Thank you Sir.
What kind of email newsletter would you prefer to receive from CodeAsp.Net?18