A simple example that shows how to work the Panel in an ASP.NET page
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Button.Text = "Hide Panel";
}
protected void Button_Click(object sender, EventArgs e)
{
PanelContent.Visible = !PanelContent.Visible;
if(PanelContent.Visible)
Button.Text = "Hide Panel";
else
Button.Text = "Show Panel";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ASP.NET Demo: Panel</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button" runat="server" Text="" OnClick="Button_Click" /><br /><br />
<asp:Panel ID="PanelContent" runat="server">
<div style="background-color: #ffd800; border:1px solid #ccc; padding:5px; ">
"<em>Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat. Quis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</em>"
</div>
</asp:Panel>
</div>
</form>
</body>
</html>
When the page is loaded for the first time the panel PanelContent is visible and the Button displays "Hide Panel"
When the Button is clicked, the Button_Click method changes the visibility of PanelContent, and the Button text: if PanelContent is visible, Button shows "Hide Panel" otherwise Button displays "Show Panel"
Category: ASP.NET