Search results

Render a dialog header dynamically in Blazor Dialog component

03 Aug 2021 / 1 minute to read

By default, the dialog is rendered without header. You can update its header dynamically using the Header property.

In the following code, the dialog header is rendered on a button click.

Copied to clipboard
@using Syncfusion.Blazor.Popups
@using Syncfusion.Blazor.Buttons

<SfButton @onclick="@OpenDialog">Open Dialog</SfButton>
<SfButton @onclick="@RenderHeader">Render Dynamic Header</SfButton>

<SfDialog Header="@Header" Width="250px" @bind-Visible="@IsVisible">
        <Content>This is a dialog without header</Content>
        <DialogButton Content="OK" IsPrimary="true" OnClick="@CloseDialog" />
        <DialogButton Content="Cancel" OnClick="@CloseDialog" />

@code {
    private string Header { get; set; }
    private bool IsVisible { get; set; } = true;

    private void OpenDialog()
        this.IsVisible = true;

    private void CloseDialog()
        this.IsVisible = false;

    private void RenderHeader()
        this.Header = "Dynamic Header";

The output will be as follows.