Parag’s Den

Dedicated to my adored friends…..

Label Web Server Control

Posted by paragdongre on November 6, 2007


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>

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>

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>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: