Congratulations to all monthly winners of May 2013 !!! They have won INR 2900 cash and INR 27497 worth prize.
Go to DotNetFunda.com
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 35112 |  Welcome, Guest!   Register  Login
Home > Tutorials > ASP.NET Tutorials > label

Silverlight Tutorials | Report a Bug in the Tutorial
Found interesting? Add this to:


asp:Label control
Label control is used to place a static, non clickable piece of text.
 
Ads
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 <span></span> HTML tag. Its properties like BackColor, ForeColor, BorderColor, BorderStyle, BorderWidth, Height etc. are implemented through style properites of <span>. 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)

Following are few properties of the Label that are very useful.
EnableViewState true/false. If false ViewState will not be maintained.
Visible true/false. If false control will not be rendered to the page
DEMO : Label Show Source Code
Ex. Example of Label Control
                        
                        // Label control code
                        <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"
                        ></asp:Label>
                        
                        // Rendered HTML code of the Label
                        <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;">
                        Example of Label Control</span>
                    
                        // Fires when Button is clicked
                        protected void ChangeLabelText(object sender, EventArgs e)
                        {
                            Label1.Text = TextBox1.Text;
                        }
                         
                    
There is one very important but rarely used properties of Label control is AssociatedControlID 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.





About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 6/20/2013 5:42:33 AM