ASPAlliance.com : The #1 Active Server Pages .NET Community The #1 ASP.NET Community
Search   Search

Subscribe   Subscribe

Powered by ORCSWeb Hosting


Site Stats


Powered By ASP.NET
 
Featured Sponsor

Featured Columnist


Featured Book
Sams Teach Yourself VB.NET in 24 Hours
Sams Teach Yourself VB.NET in 24 Hours

Find Prices
Sample Chapter


New! asp.netPRO

We publish our articles in the standard RSS format.

Powerful .NET Email Component

Code Sharing Software

Label Web Server Control

The Label web server control is one of the simplest control. The output of label web server control is the HTML <span> tag. In this discussion we will see the following aspects.

  1. How to display/assign a text with Label Web server control?
  2. How to assign a borderwidth?
  3. How to give colors for our text?

Label - How can we declare a Label control?

In the following example the usage of label web server control is explained. The property "Text" is used to assign a value (label) to the label control.

<html>
<head>
<title>Label Web Server Control</title>
</head>

<body style="font: 10pt verdana">
<h3 align=center>ASP.NET Label Server Control</h3>

<form ID="Form1" runat=server>
    <asp:label id="label1" Text="This is my FIRST ASP.NET Page!" runat="server" />
</form>

</body>
</html>

Test this Script

Label - How to dynamically assign text to a Label?

In our next example, we can observe that, we assign the text dynamically to the label control. In the page load event, the value "This is my FIRST ASP.NET Page!" is assigned to the property text.

<html>
<head>
<title>Label Web Server Control</title>

<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
    Label1.text = "This is my FIRST ASP.NET Page!"
End Sub
</script>

</head>
<body style="font: 10pt verdana">
<h3 align=center>ASP.NET Label Server Control</h3>

<form ID="Form2" runat=server>
    <asp:label id="label1" runat="server" />
</form>

</body>
</html>

Test this Script

Label - How to show tooltip, borderwidth, forecolor, bgcolor etc.

In our final example, we will see how can we make use of other properties of the label control. The properties which is shown in the following example include tooltip, borderwidth, bordercolor, backcolor and forecolor. The property, borderwidth expects a unit. That is why we have declared a variable called "bdw", which is of type unit. And to assign colors for border, background and foreground, we use the Color object. By default, the color object is not available, since we import the namespace, "system.drawing".

<%@ Import Namespace="system.drawing"%>

<html>
<head>
<title>Label Web Server Control</title>

<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
    Dim bdw as unit
    Label1.tooltip="This is my FIRST ASP.NET page!"
    Label1.BorderWidth=bdw.pixel(1)
    Label1.text = "This is my FIRST ASP.NET page!"
    Label1.bordercolor = Color.Black
    Label1.backcolor = Color.Red
    Label1.forecolor = Color.White
End Sub
</script>

</head>
<body style="font: 10pt verdana">
<h3 align=center>ASP.NET Label Server Control</h3>

<form ID="Form1" runat=server>
    <asp:label id="label1" runat="server" />
</form>

</body>
</html>

Test this Script

Send your comments to das@aspalliance.com         Back to Tutorial

 Copyright © 2000-2003 ASPAlliance.com  Page Rendered at 11/7/2009 7:21:24 PM