ASP.NET Label

ASP.NET Label
Techiio-author
Written by Sagar RabidasJanuary 24, 2022
9 min read
ASP .Net
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

In this blog, we will discuss ASP.NET Label

ASP.NET Label:-

Label control is used to show the text on the web web page. This label manipulate is used together with different controls like textboxes. It’s very common wherein the label is used with a textbox. Labels typically assist the user to offer the facts inside the text bins by the written indications. Labels are server-facet controls. We can show the text in label control via placing the text via textual content property. By way of changing its label manipulate residences, we can exchange the label controls style or look and sense. So we can personalize it as in step with our necessities.

Syntax

< asp:LabelID="Label1" runat="server" Text="Label" ></asp:Label>

How does ASP.NET Label work?

Let us see how exactly the ASP.NET label works.

  • Open a visual studio and create a new empty web application.
  • Now add a new web form, which is there in the solution explorer.
  • From the toolbox, select the label control to drag it and drop it on the web form.
  • Set its Text and ID property from the label control.
  • We need to assign the text in label control to use its text property. by setting the text value in a label text property, the text will be displayed on the label control.
  • We can change the text of the label using its text property programmatically via writing code on the asp. cs page.
  • Text= “EduCba”;

Default.aspx.cs Code

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Public partial class _Default : System.Web.UI.Page
{
Protected void page_Load(object sender, EventArgs e)
{
Label1.Test=” Welcome to EduCba”;
}
}

Properties

Label Control has its properties, which will be used to make it more enhanced.

  1. AccessKey: To add the keyboard shortcut for the label, Accesskey is used.
  2. TabIndex: It determines the index of tab control for the webserver.
  3. BackColor: To enhance the look and make it with different colors, we can use this property so that it will help to change the background color of the label.
  4. BorderColor: If we want to set the color for the label border, we can use this property.
  5. BorderWidth: This property will allow us to set a particular width for the label border.
  6. Font: We need to set the font for the text of the label then we can use this property.
  7. Forecolor: It is used to set the color for the label text.
  8. Text: Text, which needs to be displayed for the label, is used by this property.
  9. ToolTip: It provides the text to be displayed when we try to put the mouse over a label.
  10. Visible: It will allow us to set the visibility of the control on the web form.
  11. Height: It provides us to set the height of the label control.
  12. AutoSize: If we need to resize the label control automatically, it will allow us to set the value for it.
  13. BorderStyle: We can design the border of the label control as per the application requirement.
  14. flat style: It deals with the flat style appearance for the label control.
  15. Font: It will determine the font for the text of label control. It will set the value for it.
  16. TabStop: If the user can use the tab to the label control, then this property determines the value for it.
  17. TextAlign: It will provide the alignment for the text in the label control.

Example of ASP.NET Label

Below are the examples of ASP.NET Label:

Code:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebControls.aspx.cs"
Inherits="WebFormsControlls.WebControls" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 150%;
}
.auto-style2 {
margin-left: 0px;
}
.auto-style3 {
width: 102px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<h4>Fill the Employee ID in below text box:</h4>
<table class="auto-style1">
<tr>
<td class="auto-style3">
<asp:Label ID="Label1" runat="server" Text="Employee ID"></asp:Label></td>
<td>
<asp:TextBox ID="TextBox1" runat="server" CssClass="auto-style2"></asp:TextBox></td>
</tr>
<tr>
<td class="auto-style3">
<asp:Label ID="Label2" runat="server" Text="Upload a File"></asp:Label></td>
<td>
<asp:FileUpload ID="FileUpload1" runat="server" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>

Explanation of the above code: We can see in the above code that asp gives its tag to use it as a label.<asp:Label ID =Label1> determines its id. Run at is always set to be “Server” as this is server-side control. We have added 2 labels here having the text as Employee ID and upload file. We can use this Label Control Method.

  • GetPreferredSize: It is used to retrieve the rectangular area’s size into which a control can be fitted.
  • Refresh: It will immediately redraw itself and any dependent control if any. Also, force to control to invalidate its client area.
  • Select: It activates the control.
  • Show: It will display the control to the user.
  • ToString: It will return the string, which is having the name of the control.

There is some Label control given below:

AutoSizeChanged: When the value of AutoSize Property changes this occurs.

Click: When we click the Label Control, this is used.

DoubleClick: When label control is double-clicked this occurs.

GotFocus: When label control receives focus this occurs.

Leave: When input controls leave, the focus of the control label comes under the picture.

asp net
ASP NET Label
label
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Sagar Rabidas
Software Developer
Techiio-followerTechiio-followerTechiio-followerTechiio-followerTechiio-follower
+8 more
300 Blog Posts
14 Discussion Threads
Trending Technologies
15
Software40
DevOps46
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance