Skip to content

PlaceHolder

The PlaceHolder component is meant to emulate the asp:PlaceHolder control in markup and is defined in https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.placeholder?view=netframework-4.8

PlaceHolder is a simple container that renders NO wrapper element - it only renders its child content. This is useful for conditionally showing/hiding blocks of content.

Blazor Features Supported

  • ChildContent - the content to render inside the PlaceHolder
  • Visible - controls whether the content is rendered

Key Characteristic

Unlike Panel, PlaceHolder renders only its children with no wrapper element. This makes it ideal for:

  • Conditional rendering of content blocks
  • Grouping content without affecting HTML structure
  • Dynamic content placeholders

Usage Examples

Basic Usage

<PlaceHolder>
    <p>This content renders directly with no wrapper</p>
</PlaceHolder>

Renders as:

<p>This content renders directly with no wrapper</p>

Conditional Visibility

<PlaceHolder Visible="@showContent">
    <div>Only shown when showContent is true</div>
</PlaceHolder>

WebForms Syntax

<asp:PlaceHolder
    EnableTheming="True|False"
    EnableViewState="True|False"
    ID="string"
    OnDataBinding="DataBinding event handler"
    OnDisposed="Disposed event handler"
    OnInit="Init event handler"
    OnLoad="Load event handler"
    OnPreRender="PreRender event handler"
    OnUnload="Unload event handler"
    runat="server"
    SkinID="string"
    Visible="True|False"
/>

Migration Notes

When migrating from Web Forms:

  1. Remove asp: prefix and runat="server"
  2. The ID property is not rendered (use Blazor's @ref for component references)
  3. Use for conditional rendering of content blocks