Article
    C#
    ADO.Net
    .NET
    ASP.Net & Web Forms
    Custom Controls
    Web Development
    Exception Handling
    XML
    Database
    Security in .Net
    Testing
    Web Services
    Windows Services
    Windows Controls
    WCF
    AJAX
    WPF
    XAML
    Reporting
    Setup
    VB.Net
    LINQ
    JQuery
    SilverLight
    JavaScript
    HTML5
    Crystal Report
    Cloud Computing
    Share Point
    Visual C++
    MVC
    Android
    PHP
    Java
    HTML
    WordPress
    Joomla
    Products
    Drupal
    Windows Phone
    JSON
    LightSwitch
    iPhone/iPad
    Ruby on Rails
    IIS 7
    Windows 8
    CSS/CSS3
    Excel
    MS Access
    Shortcut Keys
    Visual SourceSafe
    Team Foundation Server
    APIs
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Top Contributor
Advertisement
Advertise with Us
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog

Home >> ASP.Net & Web Forms >> Literal Control in ASP.Net
Literal Control in ASP.Net
Literal Control in ASP.Net


by Pushpendra Singh on 10/20/2010 3:54:31 PM

Views: 2385       Comments: 0

Literal Control in ASP.Net

Literal control is used to write simple text on the page, you can use server side formatting options like bold, italic, underlined.

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

Literal Control in ASP.Net

We cannot change its appearance as in Label .Unlike asp:label control, there is no property like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. of Literal control.

Difference between Label Control and Literal Control

·         The main difference 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:

         i.            PassThrough: If you set this property, then the content will not be modified and rendered as is. For eg., if string contains <hr> tag then its dependent on your browser, of how it handles <hr> tag.

       ii.            Encode: If you set this property then content will be encoded and sent to browser for e.g., if your  string contains <hr> tag, then your string will be converted to &lt;Hr&gt; and sent to browser.

      iii.            Transform: 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

 

 

 

Report Abuse Form
Reason:    
 

Title :
Comment :
Text ColorBackground Color
BoldItalicUnderline
LeftCenterRightJustify
Ordered ListBulleted List
IndentOutdent
Horizontal Rule
SubscriptSuperscript
HyperlinkImage
Design ModeDesign
View HtmlHtml
     
 
Latest Article by Pushpendra SinghRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Latest BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Top Viewed ArticlesRSS Feed
    
    
    
    
    
    
    
    
    
    
Top Viewed BlogsRSS Feed
    
    
    
    
    
    
    
    
    
    
Latest Interview QuestionsRSS Feed
    
    
    
    
    
    
    
    
    
    
More...
Total Online Users: 7331
Advertisement
MindStick DataConver
Advertise with Us
  
Copyright © 2013MindStick. All Rights Reserved.