System.Web.UI.WebControls N ...


.NET Framework Class Library
Panel Class

Represents a control that acts as a container for other controls.

Namespace:  System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)
Syntax

Visual Basic (Declaration)
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public Class Panel _
    Inherits WebControl
Visual Basic (Usage)
Dim instance As Panel
C#
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class Panel : WebControl
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class Panel : public WebControl
JScript
public class Panel extends WebControl
ASP.NET
<asp:Panel />
Remarks

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

The Direction property is useful for localizing a Panel control's content to display text for languages that are written from right to left, such as Arabic or Hebrew.

The Panel control provides several properties that allow you to customize the behavior and display of its contents. Use the BackImageUrl property to display a custom image for the Panel control. Use the ScrollBars property to specify scroll bars for the control.

TopicLocation
How to: Access Controls by using the Controls CollectionBuilding ASP .NET Web Applications in Visual Studio
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications in Visual Studio
How to: Add Controls to an ASP.NET Web Page ProgrammaticallyBuilding ASP .NET Web Applications in Visual Studio
How to: Add Panel Controls to a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
How to: Add Panel Controls to a Web Forms PageBuilding ASP .NET Web Applications in Visual Studio
How to: Add Panel Controls to a Web Forms Page (Visual Studio)Building ASP .NET Web Applications in Visual Studio
How to: Add Panel Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Add Panel Web Server Controls to a Web Forms PageBuilding ASP .NET Web Applications
How to: Locate the Web Forms Controls on a Page by Walking the Controls CollectionBuilding ASP .NET Web Applications
How to: Locate the Web Forms Controls on a Page by Walking the Controls CollectionBuilding ASP .NET Web Applications
How to: Locate the Web Forms Controls on a Page by Walking the Controls CollectionBuilding ASP .NET Web Applications in Visual Studio
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications in Visual Studio
How to: Set Focus on ASP.NET Web Server ControlsBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating Accessible Web PagesBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating an Accessible Web ApplicationBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating an Accessible Web ApplicationBuilding Applications with Visual Web Developer
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding Applications with Visual Web Developer
Walkthrough: Creating and Using ASP.NET Master Pages in Visual Web DeveloperBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
Walkthrough: Data Binding to a Custom Business ObjectBuilding ASP .NET Web Applications in Visual Studio
Examples

The following example illustrates the use of a Panel control to generate controls programmatically and to hide/show a group of controls.

NoteNote:

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

Visual Basic
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
 <head>
    <title>Panel Example</title>
<script runat="server">

    Sub Page_Load(sender As Object, e As EventArgs)

        ' Show or Hide the Panel contents.
        If Check1.Checked Then
            Panel1.Visible = False
        Else
            Panel1.Visible = True
        End If

        ' Generate the Label controls.
        Dim numlabels As Integer = Int32.Parse(DropDown1.SelectedItem.Value)

        Dim i As Integer
        For i = 1 To numlabels
            Dim l As New Label()
            l.Text = "Label" + i.ToString()
            l.ID = "Label" + i.ToString()
            Panel1.Controls.Add(l)
            Panel1.Controls.Add(New LiteralControl("<br />"))
        Next i

        ' Generate the Textbox controls.
        Dim numtexts As Integer = Int32.Parse(DropDown2.SelectedItem.Value)

        For i = 1 To numtexts
            Dim t As New TextBox()
            t.Text = "TextBox" & i.ToString()
            t.ID = "TextBox" & i.ToString()
            Panel1.Controls.Add(t)
            Panel1.Controls.Add(New LiteralControl("<br />"))
        Next i
    End Sub

    </script>

 </head>
 <body>

    <h3>Panel Example</h3>

    <form id="form1" runat="server">

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

            Panel1: Here is some static content...
            <br />

       </asp:Panel>

       <br />

       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>

       <br />
       <asp:CheckBox id="Check1" Text="Hide Panel" runat="server"/>

       <br />
       <asp:Button Text="Refresh Panel" runat="server"/>


    </form>

 </body>
 </html>

C#
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html  >
 <head>
    <title>Panel Example</title>
<script runat="server">

       void Page_Load(Object sender, EventArgs e) {

          // Show or hide the Panel contents.

          if (Check1.Checked) {
             Panel1.Visible=false;
          }
          else {
             Panel1.Visible=true;
          }

          // Generate the 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 the 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>

 </head>
 <body>

    <h3>Panel Example</h3>

    <form id="form1" runat="server">

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

            Panel1: Here is some static content...
            <br />

       </asp:Panel>

       <br />

       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>

       <br />
       <asp:CheckBox id="Check1" Text="Hide Panel" runat="server"/>

       <br />
       <asp:Button Text="Refresh Panel" runat="server"/>


    </form>

 </body>
 </html>

.NET Framework Security

Inheritance Hierarchy

System..::.Object
  System.Web.UI..::.Control
    System.Web.UI.WebControls..::.WebControl
      System.Web.UI.WebControls..::.Panel
        System.Web.UI.WebControls.WebParts..::.Part
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Other Resources

Tags :


Community Content

rroyter
HTML Output
This control generates a <div> tag around its elements
Tags :

Page view tracker