Panel Control in ASP.Net


The Panel control is used as a container for other controls. This control is often used to generate controls by code and to display or hide groups of controls as per the condition.

Note: This control always renders as an HTML <div> element.

Source Code:

<asp:Panel ID="pnlMain" runat="server"
        BackImageUrl="~/Images/FunnyScraps3.jpg"
        GroupingText="This is Sample Group Text"
        HorizontalAlign="Center"
        ScrollBars="Both"
        Direction="LeftToRight"
        Wrap="true"
        DefaultButton="btnSave"
        Height="400px" Width="500px">
        <table>
            <tr>
                <td colspan="2">
                    The Panel control is used as a container for other controls. This control is often used to generate controls by code and to display and hide groups of controls.
                </td>
            </tr>
            <tr>
                <td>User Name</td>
                <td><asp:TextBox ID="txtUserID" runat="server" /></td>
            </tr>
            <tr>
                <td>User Password</td>
                <td><asp:TextBox ID="txtPassword" runat="server" TextMode="Password" /></td>
            </tr>
            <tr>
                <td>Confirm Password</td>
                <td><asp:TextBox ID="txtConfirmPassword" runat="server" TextMode="Password"/></td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <asp:Button ID="btnSave" runat="server" Text="Save" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" />
                </td>
            </tr>
        </table>
</asp:Panel>

Properties

BackImageUrl

Use to specify a URL to an image file to display as a background for this control.

1.gif
 
GroupingText

Use to specify the caption for the group of controls in the panel.

2.gif
 
DefaultButton

Use to specify the ID of the default button in the panel. This is useful to fire submit or else event when you are within this panel controls.

HorizontalAlign

Use to specify the horizontal alignment of the content. The possible values are:
  • Center
  • Justify
  • Left
  • NotSet
  • Right
3.gif

Direction

Use to specify the content display direction of the panel. The possible values for this property are:
  • LeftToRight
  • NotSet
  • RightToLeft
4.gif 

Wrap

Use to specify whether the content should wrap or not. Default is true. If the width of panel is specified and set this property as false then the content will move out from the panel.

5.gif
 
ScrollBars

Use to specify the position and visibility of scroll bars in the panel. The possible values for this property are:
  • Auto
  • Both
  • Horizontal
  • None
  • Vertical
 
6.gif


Similar Articles