asp.net - How to show and hide a Panel programmatically

Show (visible) and hide Panel programmatically
The Panel is an asp.net web server control that acts as a container control for other asp.net controls and HTML elements. Panel inside controls act as a group of controls. So we can apply common properties of the Panel's inside controls by setting the panel's properties such as showing or hiding all controls, aligning and directing controls, etc.

Panel Visible property accepts a Boolean value. if we set the Panel Visible property value to false then it hides all inside controls from the web page with the Panel itself. Panel Visible property value True means the Panel and its inside controls will render in web pages and all elements are visible to visitors.

We can control the Panel and its inside controls visibility using Panel's Visible property. The Visible property value True and False works as a switch to rendering or not rendering the Panel on the web page. The Panel acts as a parent control and the inside control as a child control.

The following asp.net c# example code demonstrates to us how can we show or hide panel server control programmatically on a web page.
PanelVisible.aspx

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

<!DOCTYPE html>

<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e)
    {
        Panel1.Visible = false;
        Label1.Text = "Panel now hide";

    }
    protected void Button2_Click(object sender, System.EventArgs e)
    {
        Panel1.Visible = true;
        Label1.Text = "Panel now visible";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>How to show, hide, visible Panel programmatically</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h2 style="color:Navy; font-style:italic;">Panel Example: Show Hide</h2>
        <asp:Label 
             ID="Label1"
             runat="server"
             ForeColor="SeaGreen"
             Font-Size="Large"
             Font-Bold="true"
             Font-Italic="true"
             >
        </asp:Label>
        <br /><br />
        <asp:Panel 
             ID="Panel1"
             runat="server"
             Height="150"
             Width="350"
             HorizontalAlign="Center"
             ForeColor="Snow"
             BackColor="DeepPink"
             Font-Size="X-Large"
             >
             <br /><br />
             Panel Visible property
        </asp:Panel>
        <br /><br />
        <asp:Button 
             ID="Button1" 
             runat="server"
             ForeColor="DarkMagenta"
             Text="Hide Panel"
             Height="45"
             OnClick="Button1_Click"
             Font-Bold="true"
             />
        <asp:Button 
             ID="Button2" 
             runat="server"
             ForeColor="DarkMagenta"
             Text="Visible Panel"
             Height="45"
             OnClick="Button2_Click"
             Font-Bold="true"
             />
    </div>
    </form>
</body>
</html>