How to use Panel control in

Panel Web Server Control
Panel is an web server control. panel control act as a container control for static text and other controls. panel works as a parent control for other controls in a web page. panel control is very useful when you want to create content programmatically and want to insert it into web page. panel control is a container for controls which you want to create at run time programmatically.

we can put controls in a panel and manage them as a group of controls. so we can show or hide all controls inside a panel by setting the panel Visible property. panel's DefaultButton property can define a default button for the panel container.

panel's Height and Width property help us to create a specific size container. then we can show scroll bars by setting the panel's ScrollBars property. ScrollBars property have five possible vales those are None, Horizontal, Vertical, Both and Auto. ScrollBars property value Auto can show scroll bars automatically when panel inside content size exceeds the panel control size. None value means no scroll bars are shown in panel. All value show both horizontal and vertical scroll bars in a panel. Horizontal and Vertical value show only horizontal or vertical scroll bar in panel control.

we can set Panel's BackColor, ForeColor, BorderColor and many other properties to apply a unique look for all controls inside the panel. it is very useful feature when you want to apply common look and colors for all controls inside a panel control.

panel HorizontalAlign property setting allow us to align child controls inside panel such as left, right, centered aligned contents. Wrap is an useful property of panel control. Wrap set a value which indicate whether contents wrap within panel control. we can wrap content to next line or truncate panel contents by setting the panel Wrap property.

panel's Direction property specify whether panel contents render from left to right or right to left. It is very useful for some asian language which are written from right to left such as Arabic or Hebrew. Direction property have three possible values such as NotSet, LeftToRgiht and RightToLeft.

panel's GroupingText property render a border and title around the panel container. GroupingText property causes scroll bars not to appear in panel.

the following c# example source code and image help you to understand more about panel web server control.

<%@ Page Language="C#" %>
<!DOCTYPE html>

<script runat="server">

<html xmlns="">
    <head runat="server">
        <title>Panel example: how to use Panel control in</title>
        <form id="form1" runat="server">
                <asp:Panel ID="Panel1" runat="server" ScrollBars="Auto" Width="450" Height="200" Wrap="true" BackColor="Aqua" Direction="LeftToRight">
                        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. 

                        Grouping Controls and Markup. 

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

                        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. 
Related examples