Label Control In ASP.NET


In this article, you will learn how to use Label in ASP.NET Framework and how Label works.

What are Label Controls

  • The label control is used to display text on a website.
  • It is primarily used to generate captions for other controls such as textboxes.
  • Labels typically assist the user in entering data into text boxes by providing written instructions.
  • Labels are controls on the server-side.
  • The Label class can be found in the System.Web.UI.WebControls namespace.

Adding Label Control

  • To create a label, we can either write code or use Visual Studio's drag and drop feature.
  • This is a server-side control, and asp provides its own tag for label creation.

The following is an example and syntax to add label control.

<asp:Label_ID="LabelNew" runat="'server" Text="Label_Control"></asp:Label>

here Runat='Server' Indicates the accessibility of the control at Serverside

Properties of Label Control

Label Control has its own properties that will be used to improve it. (Syntax for each label control property is given in ASP.NET code)


Accesskey is used to add the keyboard shortcut for the label.

<asp:webcontrol id="id" AccessKey="accessKey" runat="server" />


It determines the webserver's tab control index.

<asp:TextBox ID="txtName" runat="server" TabIndex="0"></asp:TextBox>


This property is used to change the look and make it with different colours.

<asp:webcontrol id="id" BackColor="color" runat="server" />


We can use this property to change the colour of the label border.

<asp:webcontrol id="id" BorderColor="color" runat="server" />


This property will allow us to specify the width of the label border.

<asp:webcontrol id="id" BorderWidth="length" runat="server" />


This property will allow us to specify the width of the label border.

<asp:webcontrol id="id" font-subproperty="value" runat="server" />


It's used to change the colour of the label text.

<asp:webcontrol id="id" ForeColor="color" runat="server" />


This property makes use of text that must be displayed for the label.

<asp:HyperLink Text="string" runat="server" />


It specifies the text that will be displayed when we move the mouse over a label.

<asp:webcontrol id="id" ToolTip="string" runat="server" />


It will allow us to customise the control's visibility on the web form.

<asp:webcontrol id="id" Visible="True|False" runat="server" />


It allows us to customise the height of the label control.

<asp:Image ID="Image1" runat="server" Height="value" />


It allows us to adjust the width of the label control.

<asp:Image ID="Image1" runat="server"  Width="value" />


The border of the label control can be designed to meet the needs of the application.

<asp:webcontrol id="id" BorderStyle="style" runat="server" />


It gives us the CSS class of the label control.

<asp:webcontrol id="id" CssClass="style" runat="server" />

Events for Label Controls 


When the server control binds to a data source, this is referred to as data binding.


When an ASP.NET page is requested, a server control is released from memory, which is the final stage of the server control lifecycle.


Occurs during the initialization of the server control, which is the first step in its lifecycle.


When the server control is loaded into the Page object, this event occurs.


This occurs after the Control object has been loaded but before rendering.


This happens when the server control is loaded from memory.

Methods for Label Control


Binds a data source to the server control that was invoked and all of its child controls.


Allows a server control to perform final cleanup before releasing it from memory.


Checks whether the specified object is the same as the current object.


Sets a control's input focus.


The Load event is raised.


This method returns a string that represents the current object.


Here, we have learned how label works in ASP.NET Framework and how label controls are useful for us to use.

If you have any queries/suggestions on the article, please leave your questions and thoughts in the comment section below. Follow C# Corner to learn more new and amazing things about ASP.NET or to explore more technologies.

Thanks for reading and I hope you like it.