Notification
Namespace: Wisej.Web.Ext.Notification
Assembly: Wisej.Web.Ext.Notification (4.1.0.0)
Adds support for the Notification API: notification.
- C#
- VB.NET
public class Notification : Component
Public Class Notification
Inherits Component
The component displays system (desktop) notifications in the browser of the current session. The browser asks the user for permission the first time a notification is shown; when the permission is denied or the browser doesn't support notifications, nothing is displayed and no error is returned. Browsers allow notifications only on secure (HTTPS or localhost) pages. The Click event is wired to the client only if a handler is attached when the component is rendered.
Example:
Notifying the user and reacting to the click on the notification:
public MainPage()
{
InitializeComponent();
this.notification1.Click += this.notification1_Click;
}
private void OrderReceived(string orderId)
{
this.notification1.Show("New order", "Order " + orderId + " has been received.", id: orderId, showOnClick: true);
}
private void notification1_Click(object sender, NotificationClickEventArgs e)
{
OpenOrder(e.Id);
}
Constructors
Notification()
Initializes a new instance of the Notification class.
Notification(container)
Initializes a new instance of the Notification class together with the specified container.
| Name | Type | Description |
|---|---|---|
| container | IContainer | A IContainer that represents the container for the component. |
Throws:
- ArgumentNullException container is null.
Properties
IsSupported
Boolean: Returns whether the client browser supports desktop notifications.
Value: true if the browser supports the Notification API.
This static property checks the browser of the current session (Browser). It doesn't indicate whether the user has granted the permission to display notifications.
Example:
Falling back to an in-page alert when desktop notifications are not supported:
if (Notification.IsSupported)
this.notification1.Show("Export completed", "The report is ready to download.");
else
AlertBox.Show("The report is ready to download.");
Methods
OnClick(e)
Fires the Click event.
| Parameter | Type | Description |
|---|---|---|
| e | NotificationClickEventArgs | A NotificationClickEventArgs that contains the event data. |
OnWebEvent(e)
Processes the event from the client.
| Parameter | Type | Description |
|---|---|---|
| e | WisejEventArgs | Event arguments. |
OnWebRender(config)
Renders the client component.
| Parameter | Type | Description |
|---|---|---|
| config | Object | Dynamic configuration object. |
Show(title, body, icon, showOnClick, image, id, requireInteraction)
Displays a new desktop notification.
| Parameter | Type | Description |
|---|---|---|
| title | String | The title of the notification. |
| body | String | The optional body string of the notification. |
| icon | String | The URL of the image used as an icon of the notification. |
| showOnClick | Boolean | Indicates whether to activate the browser when the user clicks the notification. |
| image | String | URL of an image to show at the top of the notification window. |
| id | String | Optional unique id, returned in NotificationClickEventArgs. |
| requireInteraction | Boolean | Indicates that a notification should remain active until the user clicks or dismisses it, rather than closing automatically. |
The notification is displayed asynchronously by the browser. If the user has not yet granted or denied the permission, the browser asks first and the notification is displayed only if the permission is granted. The language of the notification is set to the current culture (CurrentCulture). Support for image and requireInteraction depends on the browser and the operating system.
Example:
Displaying a notification that stays visible until the user dismisses it:
this.notification1.Show(
"Meeting reminder",
"Project review starts in 5 minutes.",
icon: "Images/calendar.png",
showOnClick: true,
id: "meeting-42",
requireInteraction: true);
Events
Click
NotificationClickEventHandler Fired when the user clicks on a desktop notification.
Implements
| Name | Description |
|---|---|
| IUserData | |
| IWisejComponent | |
| IWisejSerializable |