Share via


Panel Class

Provides a grouping mechanism for organizing controls.

public class System.Web.UI.MobileControls.Panel : 
   System.Web.UI.MobileControls.MobileControl,
   System.Web.UI.MobileControls.ITemplateable

Remarks

Panels exist within forms and can be recursively nested. A panel renders the controls contained inside it; attributes set on a panel can be inherited by the controls contained in that panel.

You can use a panel for any of the following functions:

  • Grouping controls logically so that they can be easily shown or hidden.
  • Defining a convenient container where controls can be dynamically created or removed.
  • Using a single point to apply style attributes to a set of controls, by setting them on the panel. Because style inheritance applies to panels, attributes set on a panel can be inherited by controls contained in that panel.
  • Providing hints to the ASP.NET page framework about which controls to keep together when paginating. By default, the contents of a panel are kept together on a page. You can modify this behavior by setting the panel's Paginate property.

You can include literal text together with its accompanying markup tags in the text contents of the Panel control. See Literal Text Inside Form Markup for more information.

Example

The first part of the code example sets a panel's properties during a page load. The second part defines functions to manipulate a panel's properties so that they respond to command clicks.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="VB" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script runat="server" language="vb">

Public Sub Page_Load(sender As Object, e As EventArgs)
   Panel1.Wrapping = Wrapping.NoWrap
   Panel1.Alignment = Alignment.Center
   Panel1.StyleReference = "title"
End Sub

Public Sub MakeFontRed(sender As Object, e As EventArgs)
   Panel1.ForeColor = System.Drawing.Color.Red
End Sub

Public Sub MakeFontBlue(sender As Object, e As EventArgs)
   Panel1.ForeColor = System.Drawing.Color.Blue
End Sub
</script>

<mobile:Form runat="server" id="Form1">
   <mobile:Panel runat="server" id="Panel1">
      <mobile:Textview runat="server" id="TextView1">
         A Panel provides a grouping mechanism for organizing controls.
      </mobile:TextView>
   </mobile:Panel>
   <mobile:Command runat="server" id="Command1" Text="Make Font Red" 
      OnClick="MakeFontRed"/>
   <mobile:Command runat="server" id="Command2" Text="Make Font Blue" 
      OnClick="MakeFontBlue"/>
</mobile:Form>
[C#]
<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="c#" %>
<%@ Register TagPrefix="mobile"
    Namespace="System.Web.UI.MobileControls"
    Assembly="System.Web.Mobile" %>

<script runat="server" language="c#">

public void Page_Load(Object sender, EventArgs e)
{
   Panel1.Wrapping = System.Web.UI.MobileControls.Wrapping.NoWrap;
   Panel1.Alignment = System.Web.UI.MobileControls.Alignment.Center;
   Panel1.StyleReference = "title";
}

public void MakeFontRed(Object sender, EventArgs e)
{
   Panel1.ForeColor = System.Drawing.Color.Red;
}

public void MakeFontBlue(Object sender, EventArgs e)
{
   Panel1.ForeColor = System.Drawing.Color.Blue;
}
</script>

<mobile:Form runat="server" id="Form1">
   <mobile:Panel runat="server" id="Panel1">
      <mobile:Textview runat="server" id="TextView1">
         A Panel provides a grouping mechanism for organizing controls.
      </mobile:TextView>
   </mobile:Panel>
   <mobile:Command runat="server" id="Command1" Text="Make Font Red" 
      OnClick="MakeFontRed"/>
   <mobile:Command runat="server" id="Command2" Text="Make Font Blue" 
      OnClick="MakeFontBlue"/>
</mobile:Form>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

See Also

Panel Control| Implementing Templated Rendering | Template Sets and Templated Controls | Organizing Content with Containers