次の方法で共有


Panel Web Server Control Overview

The Panel Web server control provides a container control in an ASP.NET Web page that you can use as a parent for static text and for other controls.

This topic contains:

  • Background

  • Code Examples

  • Class Reference

Background

You can use the Panel control as a container for other controls. This is particularly useful when you are creating content programmatically and you need a way to insert the content into the page. The following sections describe additional ways that you can use the Panel control.

Container for Dynamically Generated Controls

The Panel control provides a convenient container for controls that you create at run time. For details, see Adding ASP.NET Controls Programmatically.

Grouping Controls and Markup

You can manage a group of controls and associated markup as a unit by putting them in a Panel control and then manipulating the Panel control. For example, you can hide or show a group of controls inside a panel by setting the panel's Visible property.

Forms with Default Buttons

You can put TextBox controls and Button controls inside the Panel control and then define a default button by setting the Panel control's DefaultButton property to the ID of a button in the panel. If users press ENTER while typing in a text box inside the panel, it has the same effect as if the user had clicked the specified default button. This can help users work more efficiently with entry forms.

Adding Scrollbars to Other Controls

Some controls such as the TreeView control do not have built-in scrollbars. You can add scrolling behavior by placing the control in a Panel control. To add scrollbars to the Panel control, set the Height and Width properties to constrain the Panel control to a specific size, and then set the ScrollBars property.

Custom Areas on the Page

You can use the Panel control to create areas on the page that have custom appearance and behavior, such as the following:

  • Creating a grouping box with title   You can set the GroupingText property to display a title. When the page renders, the Panel control is displayed with a box around it that contains a title with the text you specify.

    Note

    You cannot specify both scrollbars and grouping text in the Panel control. If you set grouping text, it takes precedence over scrollbars.

  • Creating areas on the page with a custom color or other appearance   The Panel control supports appearance properties such as BackColor and BorderWidth that you can set to create a unique look for a region on a page.

    Note

    Setting the GroupingText property automatically renders a border around the Panel control.

Back to top

Code Examples

How to: Add Panel Controls to a Web Forms Page

How to: Add Controls to an ASP.NET Web Page Programmatically

Back to top

Class Reference

The following table lists the classes that relate to the Panel control.

Member

Description

Panel

The main class for the control.

Back to top

See Also

Concepts

MultiView and View Web Server Controls Overview

Reference

PlaceHolder Web Server Control Overview