Show (visible) and hide Panel programmatically
Panel is an asp.net web server control that act 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 panel's inside controls
by setting the panel's properties such as show or hide all controls, align and direction of controls etc.
Panel Visible property accept a Boolean value. if we set the Panel Visible property value to false then it hide all inside controls from web page with panel itself. Panel Visible property value True means panel and its inside controls will render in web pages and all elements are visible for visitors.
We can control the Panel and its inside controls visibility using Panel's Visible property. Visible property value True and False works as a switch to rendering or not rendering the Panel in web page. Panel act as a parent control and inside control as child controls.
The following asp.net c# example code demonstrate us how can we show or hide panel server control programmatically in a web page.
Panel Visible property accept a Boolean value. if we set the Panel Visible property value to false then it hide all inside controls from web page with panel itself. Panel Visible property value True means panel and its inside controls will render in web pages and all elements are visible for visitors.
We can control the Panel and its inside controls visibility using Panel's Visible property. Visible property value True and False works as a switch to rendering or not rendering the Panel in web page. Panel act as a parent control and inside control as child controls.
The following asp.net c# example code demonstrate us how can we show or hide panel server control programmatically in 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>


