This documentation is archived and is not being maintained.

PanelStyle Class

Note: This class is new in the .NET Framework version 2.0.

Represents the style for a Panel control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

Public Class PanelStyle
	Inherits Style
Dim instance As PanelStyle

public class PanelStyle extends Style
public class PanelStyle extends Style

The PanelStyle class is used to represent the style settings for a panel control. It encapsulates the properties that control the appearance of a panel and can be applied to multiple panel controls to provide a common appearance.

You can specify an image to display in the background of the panel by setting the BackImageUrl property. The horizontal alignment of the contents of the panel is indicated by the HorizontalAlign property. The direction of controls that contain text within the panel control can be specified by setting the Direction property.

The following code example demonstrates creating a PanelStyle object and setting its properties. This example has two parts:

A partial class, PanelStylecs_aspx, that demonstrates creating a new PanelStyle object and setting its properties.

A Web Forms page that uses the PanelStylecs_aspx example as its code-behind file.

The first part of the example demonstrates creating a PanelStyle object, myPanelStyle, and setting its properties. Then the ApplyStyle method is called for both the Panel1 panel and the Panel2 panel, and myPanelStyle is applied to both of them.

Partial Class PanelStylevb_aspx
    Inherits Page

    Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

        Dim panelState As StateBag = New StateBag()
        Dim myPanelStyle As PanelStyle = New PanelStyle(panelState)

        ' Set the properties of the PanelStyle class.
        myPanelStyle.HorizontalAlign = HorizontalAlign.Center
        myPanelStyle.ScrollBars = ScrollBars.Both
        myPanelStyle.Wrap = False
        myPanelStyle.Direction = ContentDirection.LeftToRight
        myPanelStyle.BackImageUrl = "~\images\picture.jpg"

        ' Use the ApplyStyle method of the Panel control to apply
        ' the settings from the myPanelStyle object.
    End Sub

End Class

The second part of the example shows an .aspx file that is used with the previous example.

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="PanelStyle.vb" Inherits="PanelStylevb_aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
    <form id="form1" runat="server">
      <h3>PanelStyle Example</h3>
      <asp:Panel id="Panel1" 
        This is the Panel1 panel control.
      <br /><br />
      <asp:Panel id="Panel2" 
        This is the Panel2 panel control.

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0