Share via


Panel 웹 서버 컨트롤 선언 구문

업데이트: 2007년 11월

다른 컨트롤을 위한 컨테이너 역할을 하는 컨트롤입니다. 이 컨트롤은 HTML <div> 요소로 렌더링됩니다.

<asp:Panel
    AccessKey="string"
    BackColor="color name|#dddddd"
    BackImageUrl="uri"
    BorderColor="color name|#dddddd"
    BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|
        Inset|Outset"
    BorderWidth="size"
    CssClass="string"
    DefaultButton="string"
    Direction="NotSet|LeftToRight|RightToLeft"
    Enabled="True|False"
    EnableTheming="True|False"
    EnableViewState="True|False"
    Font-Bold="True|False"
    Font-Italic="True|False"
    Font-Names="string"
    Font-Overline="True|False"
    Font-Size="string|Smaller|Larger|XX-Small|X-Small|Small|Medium|
        Large|X-Large|XX-Large"
    Font-Strikeout="True|False"
    Font-Underline="True|False"
    ForeColor="color name|#dddddd"
    GroupingText="string"
    Height="size"
    HorizontalAlign="NotSet|Left|Center|Right|Justify"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    ScrollBars="None|Horizontal|Vertical|Both|Auto"
    SkinID="string"
    Style="string"
    TabIndex="integer"
    ToolTip="string"
    Visible="True|False"
    Width="size"
    Wrap="True|False"
/>

설명

Panel 컨트롤은 다른 컨트롤을 위한 컨테이너 역할을 합니다. 이 컨트롤은 프로그래밍 방식으로 컨트롤을 생성하고 컨트롤의 그룹을 표시하거나 숨기는 데 특히 유용합니다. BackImageUrl 속성을 설정하여 Panel 컨트롤의 배경에 이미지를 표시할 수 있습니다. HorizontalAlignment 속성을 사용하면 컨트롤에 포함된 항목의 가로 맞춤을 지정할 수 있습니다. Wrap 속성을 사용하면 줄이 패널 너비보다 길 때 컨트롤의 항목을 자동으로 다음 줄에 이어 표시할지 여부를 지정할 수 있습니다.

Panel 웹 서버 컨트롤의 속성과 이벤트에 대한 자세한 내용은 Panel 클래스 설명서를 참조하십시오.

예제

아래 예제에서는 Panel 컨트롤을 사용하여 컨트롤의 그룹을 표시하고 숨기는 방법을 보여 줍니다.

참고

다음 코드 샘플에서는 단일 파일 코드 모델을 사용하며 코드 숨김 파일에 직접 복사되는 경우에는 올바르게 작동하지 않을 수 있습니다. 이 코드 샘플을 확장명이 .aspx인 빈 텍스트 파일에 복사해야 합니다. Web Forms 코드 모델에 대한 자세한 내용은 ASP.NET 웹 페이지 코드 모델을 참조하십시오.

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
 <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>

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
 <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>

참고 항목

참조

Panel

기타 리소스

웹 서버 컨트롤 구문