Skip to main content

Notification

Namespace: Wisej.Web.Ext.Notification

Assembly: Wisej.Web.Ext.Notification (4.1.0.0)

Adds support for the Notification API: notification.

public class Notification : 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​

Instance member Notification()​

Initializes a new instance of the Notification class.

Instance member Notification(container)​

Initializes a new instance of the Notification class together with the specified container.

NameTypeDescription
containerIContainerA IContainer that represents the container for the component.

Throws:

Properties​

Static member 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​

Protected member OnClick(e)​

Fires the Click event.

ParameterTypeDescription
eNotificationClickEventArgsA NotificationClickEventArgs that contains the event data.

Protected member OnWebEvent(e)​

Processes the event from the client.

ParameterTypeDescription
eWisejEventArgsEvent arguments.

Protected member OnWebRender(config)​

Renders the client component.

ParameterTypeDescription
configObjectDynamic configuration object.

Instance member Show(title, body, icon, showOnClick, image, id, requireInteraction)​

Displays a new desktop notification.

ParameterTypeDescription
titleStringThe title of the notification.
body optionalStringThe optional body string of the notification.
icon optionalStringThe URL of the image used as an icon of the notification.
showOnClick optionalBooleanIndicates whether to activate the browser when the user clicks the notification.
image optionalStringURL of an image to show at the top of the notification window.
id optionalStringOptional unique id, returned in NotificationClickEventArgs.
requireInteraction optionalBooleanIndicates 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​

Instance member Click​

NotificationClickEventHandler Fired when the user clicks on a desktop notification.

Implements​