Source view of LITERAL.ASPX
DotNet Funda: Code Viewer
literal.aspx | literal.aspx.cs
Close Window  
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHeader" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderForTitleAndIntro" Runat="Server">
    <table width="100%" cellpadding="2" cellspacing="0">
        <tr valign="top" class="ArticleTitle">
            <td style="padding-left:10px;" valign="middle">
                asp:Literal control</td>
        </tr>
        <tr>
            <td class="ArticleContents">
                Literal control is the rarely used control which is used to put static text on the web page.
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
    <div class="ArticleContents">
        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.
        <br />
        Unlike asp:Label control, there is no property like <span class="DemoCP">BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. </span> of Literal control. 
        That makes it more powerful, you can even put a pure HTML contents into it.

        <!-- START - Demo Section -->
        <table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
            <tr>
                <td class="DemoTitle">
                    DEMO : Literal
                </td>
                <td align="right">
                    <a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/controls/literal.aspx" target="_blank">Show Source Code</a>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lbl" AssociatedControlID="dropStatic" runat="Server" Text="Select color to change the background color the cell"></asp:Label>
                     <asp:DropDownList ID="dropStatic" 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="btnSubmit" runat="Server" OnClick="ChangeBackColor" Text="Change Background Color" />
                </td>
                <td <asp:Literal ID="Literal1" runat="Server" />>
                    Ex. <asp:Literal ID="litText" runat="Server" Text="Just a text inside Literal Control"></asp:Literal>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <!-- START - Server Side Code -->
                    <pre>
            &lt;tr&gt;
                &lt;td&gt;
                    &lt;asp:Label ID="Label1" AssociatedControlID="dropStatic" runat="Server" Text="Select color to change the background color the cell"&gt;&lt;/asp:Label&gt;
                     &lt;asp:DropDownList ID="DropDownList1" runat="server"&gt;
                        &lt;asp:ListItem Text="Red" Value="red"&gt;&lt;/asp:ListItem&gt;
                        &lt;asp:ListItem Text="Blue" Value="blue"&gt;&lt;/asp:ListItem&gt;
                        &lt;asp:ListItem Text="Green" Value="green"&gt;&lt;/asp:ListItem&gt;
                    &lt;/asp:DropDownList&gt;
                    &lt;asp:Button ID="Button1" runat="Server" OnClick="ChangeBackColor" Text="Change Label Text" /&gt;                
                &lt;/td&gt;
                
                // Set the background color of the cell from server side event
                &lt;td &lt;asp:Literal ID="Literal2" runat="Server" /&gt;&gt;
                    Ex. &lt;asp:Literal ID="Literal3" runat="Server" Text="Just a text inside Literal Control"&gt;&lt;/asp:Literal&gt;
                &lt;/td&gt;
            &lt;/tr&gt;
            
            
            // CODE BEHIND 
            // Fires when Button is clicked
            protected void ChangeBackColor(object sender, EventArgs e)
            {
                Literal1.Text = " bgcolor='" + dropStatic.SelectedValue + "'";
                litText.Text = "&lt;div style='background-color:white;color:#000000'&gt;Literl Control is powerful&lt;/div&gt;";
            }
                    </pre> 
                    <!-- END - Server Side Code -->
                </td>
            </tr>
        </table>
        <!-- END - Demo Section -->
        </div>
    <br />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>

Go Top