- How to change Label text programmatically

Change Label text programmatically
The Label class Represents a label control, which displays text on a Web page. The developers can use the Label control to display text in a set location on the web page. Unlike static text, c# developers can customize the displayed text through the Text property.

The following c# tutorial code demonstrates how we can programmatically change a Label control’s text. Here we used the Label web server control’s Text property to change its contained text programmatically.

The Label control Text property gets or sets the text content of the Label control. This property value is a String which is the text content of the control. The default value of this property is Empty.

The developers have to use the Text property to specify or determine the text content of the Label control. The Label control’s Text property is commonly used to programmatically customize the text that is displayed in the Label control.

The Text property can include HTML but the HTML will be passed unchanged to the browser. If the developers want the browser to display HTML markup as plain text, they can use the HtmlEncode method.

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
        Label1.Text = "You clicked the Button";

<html xmlns="">
<head id="Head1" runat="server">
    <title>How to set, change Label text programmatically</title>
    <form id="form1" runat="server">
        <h2 style="color:Navy">Label Example: Text</h2>
             Text="Click button for change This text."
        <br /><br />
             Text="Change Label Text"
More examples