TabContainer Component
The TabContainer displays content in a tabbed interface. Each TabPanel child defines a tab with a header and content area. This emulates the Ajax Control Toolkit TabContainer / TabPanel controls.
1. Basic Tabs
A simple tab container with three tabs using HeaderText for tab labels.
Welcome to the Home tab. This is the default active tab.
<TabContainer ActiveTabIndex="0">
<TabPanel HeaderText="Home">
<ContentTemplate><p>Home content.</p></ContentTemplate>
</TabPanel>
<TabPanel HeaderText="Products">
<ContentTemplate><p>Products list.</p></ContentTemplate>
</TabPanel>
</TabContainer>
2. Styled Tabs
Apply CssClass to the container for custom tab styling.
Your documents are listed here.
<TabContainer ActiveTabIndex="0" CssClass="styled-tabs">
<TabPanel HeaderText="Documents">
<ContentTemplate><p>Content.</p></ContentTemplate>
</TabPanel>
</TabContainer>
3. Disabled Tab
Set Enabled="false" on a TabPanel to disable it. The tab header appears but cannot be selected.
This tab is active and selectable.
<TabPanel HeaderText="Disabled Tab" Enabled="false">
<ContentTemplate><p>Cannot reach this.</p></ContentTemplate>
</TabPanel>
4. OnActiveTabChanged Event
Use OnActiveTabChanged to respond when the user switches tabs.
Content of Tab A.
<TabContainer ActiveTabIndex="@activeTab" OnActiveTabChanged="OnTabChanged">
<TabPanel HeaderText="Tab A">...</TabPanel>
<TabPanel HeaderText="Tab B">...</TabPanel>
</TabContainer>
@code {
private int activeTab = 0;
private void OnTabChanged(int index) { activeTab = index; }
}
5. HeaderTemplate
Use HeaderTemplate instead of HeaderText for rich tab headers with custom markup.
Items that have been approved.
<TabPanel>
<HeaderTemplate><span style="color: green;">✅ Approved</span></HeaderTemplate>
<ContentTemplate><p>Approved items.</p></ContentTemplate>
</TabPanel>
6. ScrollBars
Set ScrollBars on the container to add scrolling behavior to tab content areas.
<TabContainer ActiveTabIndex="0" ScrollBars="ScrollBars.Vertical">
<TabPanel HeaderText="Scrollable">
<ContentTemplate>...long content...</ContentTemplate>
</TabPanel>
</TabContainer>
Migration Guide: Ajax Control Toolkit to Blazor
Ajax Control Toolkit (Before)
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Tab 1">
<ContentTemplate>Content 1</ContentTemplate>
</ajaxToolkit:TabPanel>
<ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Tab 2">
<ContentTemplate>Content 2</ContentTemplate>
</ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>
Blazor with BWFC (After)
<TabContainer ActiveTabIndex="0">
<TabPanel HeaderText="Tab 1">
<ContentTemplate>Content 1</ContentTemplate>
</TabPanel>
<TabPanel HeaderText="Tab 2">
<ContentTemplate>Content 2</ContentTemplate>
</TabPanel>
</TabContainer>
Migration Steps
- Remove
asp:ScriptManager - Replace
<ajaxToolkit:TabContainer>with<TabContainer> - Replace
<ajaxToolkit:TabPanel>with<TabPanel> - Remove
runat="server"andIDattributes - Keep
HeaderText,ContentTemplate,ActiveTabIndex, andEnabledproperties unchanged - Ensure the page uses
@rendermode InteractiveServer