This documentation is archived and is not being maintained.

PanelStyle Class

Represents the style for a Panel control.

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

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public class PanelStyle : 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.

public partial class PanelStylecs_aspx : Page
    void Page_Load(object sender, EventArgs e)
        StateBag panelState = new StateBag();
        PanelStyle myPanelStyle = 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.

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

<%@ Page Language="C#" CodeFile="PanelStyle.cs" Inherits="PanelStylecs_aspx" %>

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

<html xmlns="" >
  <head runat="server">
    <title>PanelStyle Example</title>
    <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.

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0