Home

Web Control: The Label

 

Labels Fundamentals

 

Introduction

A label is text that is presented to the visitor. To create such text, you can just click anywhere on the web page and type the desired string. If you want to get text that can respond to a visitor, you can use the Label control, which is implemented by the Label class.

 

Creating a Label

To visually create a label from either Microsoft Visual Studio or Microsoft Visual Web Developer, from the Standard section of the Toolbox, drag the Label object and drop it on the form.

To manually add a label, create an <asp:Label> tag and add it to the form. Here is an example:

<%@ Page Language="C#" %>
<html>
<head>

<title>Exercise</title>
</head>
<body>

<form id="frmTimeSheet" method="post" runat="server">
  <asp:Label ID="btnFullName" runat="server"></asp:Label>
</form>

</body>
</html>

Characteristics of a Label

 

The Caption of a Label

Obviously the most significant aspect of a label is the text it displays. To specify this text, add a Text attribute to the tag and assign the desired string to it. Here is an example:

<%@ Page Language="C#" %>
<html>
<head>

<script language="JavaScript" type="text/javascript">

</script>

<title>Exercise</title>
</head>
<body>

<form id="frmTimeSheet" method="post" runat="server">
  <asp:Label ID="btnFullName" Text="Full Name:" runat="server"></asp:Label>
</form>

</body>
</html>

This would produce:

Label

As compared to simple static text of a web page, the biggest advantage of using a label is that you can programmatically update its text in response to a user's action. To do this in your code, type the ID of the label, followed by a period, followed by Text, and assign it the desired value.

 
 
 
   
 

Home Copyright © 2009-2015, FunctionX, Inc.