Panel 类

表示作为其他控件的容器的控件。

**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)

语法

声明
Public Class Panel
    Inherits WebControl
用法
Dim instance As Panel
public class Panel : WebControl
public ref class Panel : public WebControl
public class Panel extends WebControl
public class Panel extends WebControl

备注

Panel 控件是其他控件的容器。当要以编程方式生成控件、隐藏/显示一组控件或本地化一组控件时,该控件尤其有用。

Direction 属性对于本地化 Panel 控件的内容以显示从右到左书写的语言(如阿拉伯语或希伯来语)的文本非常有用。

Panel 控件提供了几个属性,使用这些属性可以自定义该控件内容的行为和显示。使用 BackImageUrl 属性为 Panel 控件显示一个自定义图像。使用 ScrollBars 属性为控件指定滚动条。

主题 位置
演练:创建具有辅助功能的 Web 应用程序 在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:到自定义业务对象的数据绑定 在 Visual Studio 中构建 ASP .NET Web 应用程序
如何:向 Web 窗体页添加 Panel 控件 (Visual Studio) 在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页 在 Visual Studio 中构建 ASP .NET Web 应用程序
演练:在 Visual Web Developer 中创建和使用 ASP.NET 母版页 使用 Visual Web Developer 生成应用程序
演练:创建具有辅助功能的 Web 应用程序 使用 Visual Web Developer 生成应用程序
如何:以编程方式向 ASP.NET 网页添加控件 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:在 ASP.NET Web 服务器控件上设置焦点 在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:到自定义业务对象的数据绑定 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:向 Web 窗体页添加 Panel 控件 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:通过遍历控件集合定位页上的 Web 窗体控件 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:以编程方式向 ASP.NET 网页添加控件 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:在 ASP.NET Web 服务器控件上设置焦点 在 Visual Studio 中生成 ASP .NET Web 应用程序
演练:到自定义业务对象的数据绑定 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:向 Web 窗体页添加 Panel 控件 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:通过遍历控件集合定位页上的 Web 窗体控件 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:以编程方式向 ASP.NET 网页添加控件 生成 ASP .NET Web 应用程序
如何:向 Web 窗体页添加 Panel Web 服务器控件 生成 ASP .NET Web 应用程序
如何:在 ASP.NET Web 服务器控件上设置焦点 生成 ASP .NET Web 应用程序
如何:通过遍历控件集合定位页上的 Web 窗体控件 生成 ASP .NET Web 应用程序

示例

下面的示例说明如何使用 Panel 控件以编程方式生成控件和隐藏/显示一组控件。

提示

以下代码示例使用单文件代码模型,当它直接复制到代码隐藏文件时可能不能正常工作。此代码示例必须被复制到具有 .aspx 扩展名的空文本文件中。有关 Web 窗体代码模型的更多信息,请参见 ASP.NET 网页代码模型

<%@ Page Language="VB" AutoEventWireup="True" %>
<html>
 <head>
 
    <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 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>
 </html>
 
<%@ Page Language="C#" AutoEventWireup="True" %>
<html>
 <head>
 
    <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 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>
 </html>
 

.NET Framework 安全性

继承层次结构

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
      System.Web.UI.WebControls.Panel
         System.Web.UI.WebControls.WebParts.Part

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

Windows 98、Windows 2000 SP4、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Panel 成员
System.Web.UI.WebControls 命名空间
WebControl
Direction
BackImageUrl
ScrollBars

其他资源

Panel Web 服务器控件