Panel¶
The Panel component is a container control that renders as a <div> element, or as a <fieldset> when the GroupingText property is set. It provides a way to group controls and apply common styling.
Original Microsoft documentation: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.panel?view=netframework-4.8
Features Supported in Blazor¶
- Child content rendering
GroupingTextproperty for fieldset/legend renderingDirectionproperty for text direction (LTR/RTL)HorizontalAlignproperty for text alignmentScrollBarsproperty for overflow controlWrapproperty for content wrapping- All style properties (BackColor, ForeColor, CssClass, etc.)
Visibleproperty to show/hide the panel
Web Forms Features NOT Supported¶
DefaultButton- JavaScript-based button targeting is not implemented
Web Forms Declarative Syntax¶
<asp:Panel
ID="string"
BackColor="color name|#dddddd"
BorderColor="color name|#dddddd"
BorderStyle="NotSet|None|Dotted|Dashed|Solid|Double|Groove|Ridge|Inset|Outset"
BorderWidth="size"
CssClass="string"
DefaultButton="string"
Direction="NotSet|LeftToRight|RightToLeft"
Enabled="True|False"
Font-Bold="True|False"
Font-Italic="True|False"
Font-Names="string"
Font-Size="string"
ForeColor="color name|#dddddd"
GroupingText="string"
Height="size"
HorizontalAlign="NotSet|Left|Center|Right|Justify"
ScrollBars="None|Horizontal|Vertical|Both|Auto"
Visible="True|False"
Width="size"
Wrap="True|False"
runat="server">
<!-- Child content here -->
</asp:Panel>
Blazor Syntax¶
Basic Panel¶
Panel with CSS Class¶
Panel with GroupingText (Fieldset)¶
When GroupingText is set, the Panel renders as a <fieldset> with a <legend>:
<Panel GroupingText="Personal Information">
<Label Text="Name:" />
<TextBox @bind-Text="name" />
<br />
<Label Text="Email:" />
<TextBox @bind-Text="email" TextMode="TextBoxMode.Email" />
</Panel>
Renders as:
Panel with ScrollBars¶
<Panel ScrollBars="ScrollBars.Auto" Height="Unit.Pixel(200)" Width="Unit.Pixel(300)">
<p>This content can scroll if it overflows the panel dimensions.</p>
<!-- lots of content -->
</Panel>
Panel with Text Direction (RTL)¶
Panel with Horizontal Alignment¶
Panel with No Wrap¶
Styled Panel¶
@using static BlazorWebFormsComponents.WebColor
<Panel BackColor="LightGray"
ForeColor="DarkBlue"
BorderColor="Navy"
BorderWidth="Unit.Pixel(1)"
BorderStyle="BorderStyle.Solid">
<p>Styled panel content.</p>
</Panel>
Conditionally Visible Panel¶
<CheckBox Text="Show Details" @bind-Checked="showDetails" />
<Panel Visible="@showDetails">
<p>These are the details that can be shown or hidden.</p>
</Panel>
@code {
private bool showDetails = false;
}
HTML Output¶
Default Panel (div)¶
Blazor:
Rendered HTML:
Panel with GroupingText (fieldset)¶
Blazor:
Rendered HTML:
ScrollBars Property Values¶
| Value | CSS Output |
|---|---|
ScrollBars.None |
No overflow style |
ScrollBars.Horizontal |
overflow-x:scroll; overflow-y:hidden |
ScrollBars.Vertical |
overflow-x:hidden; overflow-y:scroll |
ScrollBars.Both |
overflow:scroll |
ScrollBars.Auto |
overflow:auto |
Migration Notes¶
When migrating from Web Forms to Blazor:
- Remove the
asp:prefix andrunat="server"attribute - Replace
IDwith@refif you need a component reference - The
DefaultButtonproperty is not implemented - use JavaScript or Blazor event handling instead - Use
ChildContentpattern (content between tags) for child controls
Before (Web Forms):¶
<asp:Panel ID="pnlDetails"
CssClass="details-panel"
Visible="true"
runat="server">
<p>Panel content</p>
</asp:Panel>
After (Blazor):¶
See Also¶
- PlaceHolder - Container with no wrapper element
- Label - Display text