Search
Author
ASP.NET Tutorials
Author
Sheo Narayan
Advertisements


Winners

Win Prizes

Social Presence
Like us on Facebook

Silverlight Tutorials | Report a Bug in the Tutorial
asp:Literal control
Literal control is the rarely used control which is used to put static text on the web page.
 
Ideally Literal control is the rarely used control which is used to put static text on the web page. When it is rendered on the page, it is implemented just as a simple text.
Unlike asp:Label control, there is no property like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. of Literal control. That makes it more powerful, you can even put a pure HTML contents into it.
DEMO : Literal Show Source Code
Ex. Just a text inside Literal Control
            <tr>
                <td>
                    <asp:Label ID="Label1" AssociatedControlID="dropStatic" runat="Server" Text="Select color to change the background color the cell"></asp:Label>
                     <asp:DropDownList ID="DropDownList1" runat="server">
                        <asp:ListItem Text="Red" Value="red"></asp:ListItem>
                        <asp:ListItem Text="Blue" Value="blue"></asp:ListItem>
                        <asp:ListItem Text="Green" Value="green"></asp:ListItem>
                    </asp:DropDownList>
                    <asp:Button ID="Button1" runat="Server" OnClick="ChangeBackColor" Text="Change Label Text" />                
                </td>
                
                // Set the background color of the cell from server side event
                <td <asp:Literal ID="Literal2" runat="Server" />>
                    Ex. <asp:Literal ID="Literal3" runat="Server" Text="Just a text inside Literal Control"></asp:Literal>
                </td>
            </tr>
            
            
            // CODE BEHIND 
            // Fires when Button is clicked
            protected void ChangeBackColor(object sender, EventArgs e)
            {
                Literal1.Text = " bgcolor='" + dropStatic.SelectedValue + "'";
                litText.Text = "<div style='background-color:white;color:#000000'>Literl Control is powerful</div>";
            }