Introduction
The label control is used to display the text that the user control edit. The Label control exists within the System.Web.UI.WebControls namespace. Here is the class hierarchy of the Label class:System.Object
System.Web.UI.Control
System.Web.UI. WebControls.WebControl
System.Web.UI.WebControls.Label
Public Properties of the Label Class
AssociatedControlID : Obtains or sets the identifier for a server control the Label control is associated with.Text : Obtains or sets the text content of the Label control.
Lets take an simple example
<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label2.Text = "Associated Control Id Example";
}
</script>
<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="<u>U</u>serName" AccessKey="U"
AssociatedControlID="TextBox1"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Check Data"
onclick="Button1_Click" />
<br />
<asp:Label ID="Label2" runat="server"></asp:Label>
</div>
</form>
</body>
</html>