asp.net.ph

Skip Navigation Links

Panel Control Syntax

ASP.NET Syntax   ASP.NET Syntax for Web Controls


Provides a container for other controls. This control is rendered as an HTML <div> element.

Declarative Syntax

For information on the individual members of this class, see Panel in the class library.

Remarks

The Panel control is a container for other controls. It is especially useful when you want to generate controls programmatically or hide/show a group of controls.

For additionl information, see Panel Web Server Control and the Panel Class documentation.

Syntax Example

The below code snippet demonstrates how to use a Panel control.

Within the <head> of the Web Forms page:

<script language="C#" runat="server">
   void Page_Load ( Object sender, EventArgs e ) {
      // show/Hide Panel Contents
      if ( Check1.Checked ) {
         Panel1.Visible=false;
      }
      else {
         Panel1.Visible=true;
      }

      // generate label controls
      int numlabels = Int32.Parse ( DropDown1.SelectedItem.Value );
      for ( int i=1; i<=numlabels; i++ ) {
         Label l = new Label ( );
         l.Text = "Label" + ( i ).ToString ( );
         l.ID = "Label" + ( i ).ToString ( );
         Panel1.Controls.Add ( l );
         Panel1.Controls.Add ( new LiteralControl ( "<br>" ) );
      }

      // generate textbox controls
      int numtexts = Int32.Parse ( DropDown2.SelectedItem.Value );
      for ( int i=1; i<=numtexts; i++ ) {
         TextBox t = new TextBox ( );
         t.Text = "TextBox" + ( i ).ToString ( );
         t.ID = "TextBox" + ( i ).ToString ( );
         Panel1.Controls.Add ( t );
         Panel1.Controls.Add ( new LiteralControl ( "<br>" ) );
      }
   }
</script>
  C# VB

Within the <body> of the Web Forms page:

<body>
   <form runat=server>
      <asp:Panel id="Panel1" runat="server"
         BackColor = "gainsboro"
         Height = "200px"
         Width = "300px">

         Panel1: Here is some static content...
         <p>
      </asp:Panel>
      <p>Generate Labels:
      <asp:DropDownList id=DropDown1 runat="server">
         <asp:ListItem Value = "0">0</asp:ListItem>
         <asp:ListItem Value = "1">1</asp:ListItem>
         <asp:ListItem Value = "2">2</asp:ListItem>
         <asp:ListItem Value = "3">3</asp:ListItem>
         <asp:ListItem Value = "4">4</asp:ListItem>
      </asp:DropDownList>
      <br>
      Generate TextBoxes:
      <asp:DropDownList id=DropDown2 runat="server">
         <asp:ListItem Value = "0">0</asp:ListItem>
         <asp:ListItem Value = "1">1</asp:ListItem>
         <asp:ListItem Value = "2">2</asp:ListItem>
         <asp:ListItem Value = "3">3</asp:ListItem>
         <asp:ListItem Value = "4">4</asp:ListItem>
      </asp:DropDownList>
      <p>
      <asp:CheckBox id="Check1" 
         Text = "Hide Panel" runat="server" />
      <p>
      <asp:Button Text = "Refresh Panel" runat="server" />

     </form>
</body>

 Show me 

See Also

Panel Class   Panel Web Server Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note