asp.net - How to hide and visible a Label programmatically

Hide and visible Label programmatically
Label is an asp.net web server control. this web server control is used to display text on web page. label is an built in property to show or hide label control programmatically at run time.

Label control's Visible property get or set a value that indicate whether the label control is rendered as UI on web page. so, by using this Visible property we can get whether the label control is visible or hidden in web browser. we also can set the label visible or hide programmatically in web page.

The label Visible property value type is System.Boolean. so, this property only accept true or false value. if we set this property value to false then it will be hide label control from web page and if we set the Visible property value to true it will show the label in web page.

The following asp.net c# example code demonstrate us how can we show or hide a label control dynamically at run time in an asp.net application's web page.
LabelVisible.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Label1.Visible = false;
    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Label1.Visible = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to show, hide, visible Label programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Teal">Label Example: Visible, Hide</h2>
        <asp:Label 
             ID="Label1" 
             runat="server"
             Text="Click button for show hide Label."
             ForeColor="Maroon"
             Font-Size="Large"
             >
        </asp:Label>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server" 
             ForeColor="RoyalBlue"
             Text="Hide Label"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server" 
             Font-Bold="true"
             ForeColor="RoyalBlue"
             Text="Visible Label"
             OnClick="Button2_Click"
             />
    </div>
    </form>
</body>
</html>
More asp.net examples