---
title: "Literal Control in ASP.Net"  
description: "A Literal control is used to write simple text on the page, you can use server side formatting options like bold, italic, underlined  aspLiteral ID"  
author: "Pushpendra Singh"  
published: 2010-10-20  
updated: 2020-04-22  
canonical: https://www.mindstick.com/articles/173/literal-control-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net"]  
reading_time: 2 minutes  

---

# Literal Control in ASP.Net

A [Literal control](https://www.mindstick.com/interview/1837/what-is-the-difference-between-a-label-control-and-a-literal-control) is used to write simple text on the page, you can use [server side](https://www.mindstick.com/forum/143/close-popup-window-by-server-side-code) formatting options like bold, italic, [underlined](https://www.mindstick.com/articles/597/creating-crystal-report-in-c-sharp-dot-net).\

```
<asp:Literal ID="Literal1" runat="server" Text="Hello"></asp:Literal>
```

![Literal Control in ASP.Net](https://www.mindstick.com/mindstickarticle/72cc1085-93d0-4f80-adf4-ffdc3d6e8014/images/ec81ce29-bbaf-48aa-b6ff-3f5d8b9ea221.png)

We cannot change its [appearance as](https://answers.mindstick.com/qa/46925/ethel-merman-made-a-cameo-appearance-as-a-man-who-thinks-he-s-singer-ethel-merman-in-what-1980-film) in Label .Unlike asp:[label control](https://www.mindstick.com/articles/301/a-label-control-in-vb-dot-net), there is no [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. of Literal control.

### Difference between Label Control and Literal Control

- The main [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) is, you can apply style to a Label control where as you can not apply styles in a literal control.
- Label control renders as span tag in a webpage while Literal Control only shows the text without any tag associated to it.
- Literal control does not maintain its viewstate.

ASP.NET Literal itself is a class which is present under System.Web.UI namespace.

### Literal Mode property:

- PassThrough: If you set this property, then the content will not be modified and rendered as is. For eg., if [string contains](https://www.mindstick.com/forum/159365/how-to-check-if-a-string-contains-letters-only-in-sql) <hr> tag then its dependent on your browser, of how it handles <hr> tag.
- Encode: If you set this property then content will be encoded and sent to browser for e.g., [if your](https://yourviews.mindstick.com/view/83528/what-to-do-if-your-eye-glasses-don-t-fit) string contains <hr> tag, then your string will be converted to &lt;Hr&gt; and sent to browser.
- [Transform](https://www.mindstick.com/interview/511/what-are-the-steps-to-transform-xml-into-html-using-xsl): If you set Mode property to Transform then the string render depends upon the type of the markup.

### Code:

```
<asp:Literal ID="Literal1" runat="server"></asp:Literal>         <br />         <asp:Literal ID="Literal2" runat="server" Mode="PassThrough"></asp:Literal>            <br />           <asp:Literal ID="Literal3" runat="server" Mode="Encode"></asp:Literal>  protected void Page_Load(object sender, EventArgs e)    {         Literal1.Text = "<hr>Hello from literal";          Literal2.Text = "<hr>hr tag enclosed with mode PassThrough";          Literal3.Text = "<hr>hr tag enclosed with mode Encode";      }
```

![Literal Control in ASP.Net](https://www.mindstick.com/mindstickarticle/72cc1085-93d0-4f80-adf4-ffdc3d6e8014/images/331f3017-eef3-480b-a488-eaabd6ba5b7a.png)

---

Original Source: https://www.mindstick.com/articles/173/literal-control-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
