drupal stats

Label

Changing Label style on mouseover

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!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>

<style type="text/css" >

   .DefaultStyle {

      background-color: Green;

   }

 

   .HoverStyle {

      background-color: Purple;

   }

</style>

</head>

<body>

    <form id="form1" runat="server">

 <asp:Label runat="server" ID="Label1" Width="250px" CssClass="DefaultStyle" 

        onmouseover="this.className='HoverStyle'" 

        onmouseout="this.className='DefaultStyle'">OnMouseOver for a Label control</asp:Label>

    </form>

    </body>

</html>

Set Label background

Set Label background color

Label1.Text = "Label background color";

Label1.BackColor = System.Drawing.Color.Blue;

Label background color thumb Set Label background

 

Set Label background image

<asp:Label ID="Label2" runat="server" Text="Label background image" Style="background-image: url(background.jpg)"></asp:Label>

Label background image thumb Set Label background

Adding OnClick Event to Label Control

Javascript function

<script type="text/javascript">

    function popup()

    {

        alert("I'm label control");

        return false;

    }

</script>

Add following line to “Page_Load”

Label1.Attributes.Add("onClick", "popup();");

zip Adding OnClick Event to Label Control DOWNLOAD [4 Kb .zip]

Hiding Label using Javascript

Javascript function for hiding label

<script type="text/javascript">

    function HideLabel()

    {

        document.getElementById('<%=Label1.ClientID%>').style.display = 'none';

        return false;

    }

</script>

Complete Source Code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!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 id="Head1" runat="server">

    <title></title>

    

<script type="text/javascript">

    function HideLabel()

    {

        document.getElementById('<%=Label1.ClientID%>').style.display = 'none';

        return false;

    }

</script>

 

</head>

<body>

    <form id="form1" runat="server">

    <div>    

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

    </div>

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return HideLabel();"/>

    </form>

</body>

</html>

Change Label Value using Javascript

Javascript function for changing label value

<script type="text/javascript">

    function ChangeLabelValue()

    {

        document.getElementById("Label1").innerHTML = "new text value"; 

    }

</script>

Complete Source Code

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<!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 id="Head1" runat="server">

    <title></title>

    

<script type="text/javascript">

    function ChangeLabelValue()

    {

        document.getElementById("Label1").innerHTML = "new text value"; 

    }

</script>

 

</head>

<body>

    <form id="form1" runat="server">

    <div>    

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

    </div>

    <input id="Button1" type="button" value="Change Label Color" onclick="ChangeLabelValue();"/>    

    </form>

</body>

</html>

Page 1 of 212