Label Control

Label Control Definition:

The Label control is Asp.net web control used to display data on a web page in asp.net development. The text is programmable Dynamic or static. Basically it is use for display message.

Asp.net Label Declare : 



<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

ID is use to Access control for C#programming Language.

Use of Asp.net Label:

Asp.net label control use to show data, in this we can display static data, fix data by property or bind data (Text) by C# code. We can also access label control by JavaScript on page.

Access Label using JavaScript:

Var lbl=document.getbyID(‘<%ControlID%>);

label control Properties :

Basically there are two impotent properties runat and text
Runat:  specify this control Execute on server site.
Text:  specify what we can display in this control.

Standard Properties of label Asp control:

BackColor of label, BorderColor of label, BorderStyle of label, BorderWidth of label, CssClass of label, Enabled of label, Font of label, EnableTheming of label, ForeColor of label, Height of label, IsEnabled of label, SkinID of label, Style of label, TabIndex of label, ToolTip of label, Width of label.

Label Control Standard Properties:

AppRelativeTemplateSourceDirectory of label, BindingContainer of label, ClientID of label of label, Controls of label, EnableTheming of label, EnableViewState of label, ID of control, NamingContainer of control, TemplateControl, TemplateSourceDirectory, UniqueID of control, Visible.

Example of Label control:

Label: In the Label control Example we take five labels with different-2 type. With different properties.
<div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>   
        <br />

        <asp:Label ID="Label2" runat="server" Font-Bold="True" Font-Size="X-Large"
            Text="Label"></asp:Label>
        <br />

        <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Size="Xx-Large"
            ForeColor="Red" Text="Label"></asp:Label>
        <br />

        <asp:Label ID="Label4" runat="server" BorderColor="#999999"
            BorderStyle="Groove" Font-Bold="True" Font-Size="XX-Large" Text="Label"
            ToolTip="Label"></asp:Label>
       <br />

        <asp:Label ID="Label5" runat="server" BackColor="#666666" BorderColor="#993300"
            BorderWidth="2px" Font-Bold="True" Font-Size="XX-Large" Height="75px"
            Text="Label" Width="289px"></asp:Label>
        <br />
   
    </div>



Asp.net label control
Asp.net label control

Asp label in Programming with example



In this Label Example we take one button control and one Label. After Execute click event then Message will be display that "Button clicked".

Label code for aspx page :



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Label_Control.aspx.cs" Inherits="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 runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div><h1>Label Example with button </h1>   
    </div>
    <div>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />   

    </div>
    </form>
</body>
</html>

Label control code for aspx.cs  page :


using System;

using System.Collections.Generic;

using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Label_Control : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Button clicked";
    }
}

Reference :

Popular posts from this blog