How to change Label text from JavaScript in asp.net

asp.net example - label javascript change text
we can change the asp.net label control's text programmatically by setting up it's text property. it is very easy and simple. but if we want to change the label server control's text using javascript and on click event, then how can we do this. in this example i show how we can change the label control text using javascript. here we uses label control's attributes property and adding here a label onclick event. this event change the label's inner text.
label-javascript-change-text.aspx

<%@ Page Language="C#" AutoEventWireup="true"%>  
    
<!DOCTYPE html>
      
<script runat="server">
    void Page_Load(object sender, EventArgs e)
    {
        Label1.Attributes.Add("OnClick", "javascript:document.getElementById('Label1').innerHTML = 'text updated.';");
    }
</script>      
      
<html xmlns="http://www.w3.org/1999/xhtml">      
<head id="Head1" runat="server">      
    <title>asp.net example - label javascript change text</title>
</head>      
<body>      
    <form id="form1" runat="server">      
    <div>      
        <h2 style="color:MidnightBlue; font-style:italic;">      
            asp.net example - label javascript change text
        </h2>      
        <hr width="550" align="left" color="Gainsboro" />      
        <asp:Label       
            ID="Label1"       
            runat="server"      
            Text="click here to change label text."
            Font-Size="XX-Large"
            ForeColor="Red"
            >      
        </asp:Label>      
    </div>      
    </form>      
</body>      
</html>
More asp.net examples