Source view of LABEL.ASPX
DotNet Funda: Code Viewer
label.aspx | label.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">
                <!-- START - Title of the topic  -->
                asp:Label control
                <!-- END- Title of the topic  -->
            </td>
        </tr>
        <tr>
            <td class="ArticleContents">
                <!-- START - Brief description of the topic -->
                Label control is used to place a static, non clickable piece of text.
                <!-- END - Brief description of the topic -->
            </td>
        </tr>
        <tr>
            <td colspan="2">&nbsp;</td>
        </tr>
    </table>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderForContents" Runat="Server">
    <div class="ArticleContents">
        <!-- START - Detailed description of the topic -->
        Ideally Label control is used to place a static, non clickable (can't fire onclick event) piece of text on
        the page. When it is rendered on the page, it is implemented through &lt;span&gt;&lt;/span&gt; HTML tag.
        Its properties like <span class="DemoCP">BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. </span>
        are implemented through style properites of &lt;span&gt;. 
        You can set its Text property either by setting Text properties in the .aspx page or from server side page. (other properties can also be set from both pages)
        <!-- END - Detailed description of the topic -->
        
        
        <!-- START- Properties or methods of this topic to define -->
        
        <br /><br />
        Following are few properties of the Label that are very useful.
        <table width="100%" class="TutoPropPlaceHolder" border="1" cellpadding="2" cellspacing="1">
            <tr>
                <td class="DemoCP">EnableViewState</td>
                <td>
                    true/false. If false ViewState will not be maintained.
                </td>
            </tr>
            <tr>
                <td class="DemoCP">Visible</td>
                <td>
                    true/false. If false control will not be rendered to the page
                </td>
            </tr>
        </table>
        <!-- END- Properties or methods of this topic to define -->
        
        <!-- START - Demo Section -->
        <table class="DemoPlaceHolder" border="1" cellpadding="2" cellspacing="4">
            <tr>
                <td class="DemoTitle">
                    DEMO : Label
                </td>
                <td align="right">
                    <!-- START - Source Viewer link, Only change the pagename (querystring) value -->
                    <a class="DemoShowSource" href="../../misc/codeviewer/default.aspx?pagename=~/tutorials/controls/label.aspx" target="_blank">Show Source Code</a>
                    <!-- END - Source Viewer link -->
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lbl" AssociatedControlID="TextBox1" runat="Server" Text="Write something into the TextBox"></asp:Label>
                    <asp:TextBox ID="TextBox1" runat="Server"></asp:TextBox>
                    <asp:Button ID="btnSubmit" runat="Server" OnClick="ChangeLabelText" Text="Change Label Text" />                
                </td>
                <td>
                    Ex. <asp:Label ID="Label1" runat="server" BackColor="Coral" ForeColor="blue" BorderColor="ActiveBorder" BorderStyle="dashed" BorderWidth="1" Height="20" Text="Example of Label Control" Width="200" ></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    
                    <pre>
                        <!-- START - ASP.NET or C# Code (replace < to &lt; and > to &gt; -->
                        // Label control code
                        &lt;asp:Label ID="Label2" runat="server" BackColor="Coral" 
                        ForeColor="blue" BorderColor="ActiveBorder" 
                        BorderStyle="dashed" BorderWidth="1" Height="20" 
                        Text="Example of Label Control" Width="200"
                        &gt;&lt;/asp:Label&gt;
                        
                        // Rendered HTML code of the Label
                        &lt;span id="ctl00_PlaceHolderForContents_Label1" 
                        style="display:inline-block;color:Blue;
                        background-color:Coral;
                        border-color:activeborder;border-width:1px;
                        border-style:Dashed;
                        height:20px;width:200px;"&gt;
                        Example of Label Control&lt;/span&gt;
                    
                        // Fires when Button is clicked
                        protected void ChangeLabelText(object sender, EventArgs e)
                        {
                            Label1.Text = TextBox1.Text;
                        }
                         <!-- START - ASP.NET or C# Code (replace < to &lt; and > to &gt; -->
                    </pre> 
                </td>
            </tr>
        </table>
        <!-- END - Demo Section -->
        
        <!-- START - Any other description about any properties of the Topic -->
        There is one very important but rarely used properties of Label control is <span class="DemoCP">AssociatedControlID</span> that is used to associate a Label with a particular Control. Like in this example, 
        Click anywhere in the page except "Write something into the TextBox" in the demo box then click "Write something into the TextBox" and notice that Cursor is placed in the TextBox.
        <!-- END - Any other description about any properties of the Topic -->
        </div>
    <br />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PlaceHolderFooter" Runat="Server">
</asp:Content>

Go Top