Blazor Notification Overview

This article provides information about the Blazor Notification component and its main features.

ninja-iconThe Notification component is part of Telerik UI for Blazor, a professional grade UI library with 110+ native components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.Start Free Trial

The Notification component renders a brief message to the user which holds information regarding the status of a process in the application. Using its settings you can customize its position, animation options and rendering.

Creating Blazor Notification

  1. Add the <TelerikNotification> tag to your razor page.
  2. Obtain the component reference via @ref.
  3. Setup an instance of the NotificationModel class (provided by the Telerik Blazor package), and pass it to the Show() method of the component instance.
@* This shows a simple text message that hides automatically *@

<TelerikButton OnClick="@AddNotification">Add a basic notification</TelerikButton>

<TelerikNotification @ref="@NotificationReference" Class="MyTelerikNotification"></TelerikNotification>

@code {
    public TelerikNotification NotificationReference { get; set; }

    public void AddNotification()
    {
        NotificationReference.Show(new NotificationModel()
        {
            Text = "Auto Closable Notification",
            ThemeColor = ThemeConstants.Notification.ThemeColor.Primary
        });
    }
}

<style>
    .MyTelerikNotification .k-notification-container .k-notification {
        width: 300px;
        height: 50px;
        font-size: 1.5em;
        text-align: center;
        align-items: center;
    }
</style>

Simple Notification

notification overview

Stacked Notifications

Multiple Notifications can stack if they derive from different references. Read the Stacked Notifications article for more information...

Templates

You can customize the rendering of the Notification by using Templates. To learn more about this feature, refer to the Notification Templates article.

Notification Parameters

ParameterType and Default valueDescription
ClassstringThe CSS class that will be rendered on the main wrapping element of the Notification component - <div class="k-notification-container">. You could use that class to to control things like the size or the z-index of the component. You can find more infomation and examples in the Appearance article.
OnChangeEventCallback<bool>This event indicates whether the media query string provided to the Media parameter matches the current browser size. It fires when it matches, and when it stops matching. See the Events article for more information.
AnimationTypeAnimationType enum
Fade
Allows you to customize the animation of the Notifications. You can find more infomation and examples in the Appearance article.
AnimationDurationint
300
Defines the duration of the animation in milliseconds.
VerticalPositionNotificationVerticalPosition enum
Bottom
Defines the vertical position of the Notification.
HorizontalPositionNotificationHorizontalPosition enum
Right
Defines the horizontal position of the Notification.

NotificationModel Class Properties

The NotificationModel class is used to add new notifications to the page. You can use it to set settings for each individual message you want to show. The class contains the following properties:

PropertyType and Default valueDescription
ThemeColorstringThe color of the notification is controlled through this parameter. You can find more infomation and examples in the Appearance article.
Closablebool
true
If set to true a close button will appear which will enable the user to close the Notification. If you want the Notification to not close automatically you should set the Closable parameter to true and the CloseAfter to 0.
CloseAfterint
5000
Allows you to configure after how much time the Notification component will close automatically. Set it to 0 to prevent it from closing automatically.
ShowIconbool
true
Allows you to specify whether an icon should appear in the component.
IconstringSpecifies the icon that will render in the component if the ShowIcon parameter is set to true. You can find more information on adding an icon to a Telerik Component in Telerik Font Icons article.
TextstringThe text that will be rendered in the Notification component.

Styling and Appearance

You can customize the appearance and styling of the Notification component by changing the notifications' colors, animation type, size, and stack order. For more information, see the Notification Appearance article.

Notifications Reference and Methods

To use the Blazor Notification methods, you have to get a reference to the component instance by using the @ref directive (example below).

MethodDescription
ShowThis method displays a new notification and has two different overloads available. The first overload receives a single parameter of type NotificationModel. The second overload accepts two string parameters, namely the notification's text and its theme color.
HideThis method accepts a NotificationModel reference as a parameter and hides the corresponding notification.
HideAllThis method hides all notifications.

Get reference to the Notification and execute methods

<TelerikButton OnClick="@OpenNotification">Open a notification</TelerikButton>

<TelerikNotification @ref="@NotificationReference" />

@code {
    private TelerikNotification NotificationReference { get; set; }

    private void OpenNotification()
    {
        NotificationReference.Show("Notification Text", "success");
    }
}

You can find more information on opening, closing and hiding the Notification in the Open, Close and Hide article.

Next Steps

See Also