Introduction of Label Control In ASP.NET
Label Control (Class)
Namespace Name :- System.Web.UI.WebControls
Assembly Name :- System.Web
Label control is used to display text on the web page.
It is a passive control, which means when we click on it, no event fire.
List of some Label control property
1) Text :- The Label control display the text(string) that is set in the Text property.
2) BackColor :- Set the background color of the Label Control.
3) ForeColor :- Set the forecolor (color of text) of the Label Control.
4) Id :- Represent the unique id for the Label Control. Further we can access the text of Label Control with the help of id.(mandatory)
5) Runat :- Enable the control to run at server side. (mandatory)
NOTE :- When we place the Label Control on the Web Page in ASP.NET, the rendered tag for the Label Control is "span" tag.
====================================================================
Create a Web Form in Visual Studio and Named it "LabelControlDemo.aspx"
====================================================================
Write the following code in the Source part of web form
====================================================================
<%@ PageLanguage="C#"AutoEventWireup="true"CodeFile="LabelControlDemo.aspx.cs"Inherits="LabelControlDemo"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1"
runat="server"
Text="<b>Hi, I am a Label Control</b>"
Font-Italic="true"
ForeColor="Aqua"
BackColor="Pink">
</asp:Label>
</div>
</form>
</body>
</html>
====================================================================
OUTPUT
====================================================================
====================================================================
RENDERED TAG FOR LABEL CONTROL
====================================================================
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="LabelControlDemo.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNjAyNTM2MTM0ZGTZP5wHpifL9sfL3T4vX/bMZbD3POM9MxaOyFhZ4UECXQ==" />
</div>
<div>
<span id="Label1" style="color:Aqua;background-color:Pink;font-style:italic;"><b>Hi, I am a Label Control</b></span>
</div>
</form>
</body>
</html>
Introduction of Label Control In ASP.NET
Reviewed by Baljeet Singh
on
22:58
Rating:
No comments: