Hi, I would like to know how can I send or push notification to the user to the browser using asp.net web forms? Something like the below image
You should use javascript plugin provided by Mozilla Developers Network
https://developer.mozilla.org/en-US/docs/Web/API/notification
If you want to trigger notifications from the server side, rather than from the client side, then take a look at SignalR:
http://signalr.net/
There is a plugin also available here https://alxgbsn.co.uk/2013/02/20/notify-js-a-handy-wrapper-for-the-web-notifications-api/
Its working sample here https://alexgibson.github.io/notify.js/
There is another way to add push notification in your website without using much of the code,that is using https://subscribers.com/ you just need to add some javascript on your website or add code in your GTM and that's it you are done.
Subscribers allows you to create "Welcome Drip" also, with the help of which if user subscribe to your website, you can send user some notifications as Welcome messages.
You can create notifications using Javascript, here is sample JS code
(async () => {
// create and show the notification
const showNotification = () => {
// create a new notification
const notification = new Notification('JavaScript Notification Example', {
body: 'This is a JavaScript Notification API demo',
icon: './img/js.png'
});
// close the notification after 10 seconds
setTimeout(() => {
notification.close();
}, 10 * 1000);
// navigate to a URL when clicked
notification.addEventListener('click', () => {
window.open('https://qawithexperts.com/questions/173/how-to-send-browser-push-notification-using-aspnet-web-forms', '_blank');
});
}
// show an error message
const showError = () => {
const error = document.querySelector('.error');
error.style.display = 'block';
error.textContent = 'You blocked the notifications';
}
// check notification permission
let granted = false;
if (Notification.permission === 'granted') {
granted = true;
} else if (Notification.permission !== 'denied') {
let permission = await Notification.requestPermission();
granted = permission === 'granted' ? true : false;
}
// show notification or error
granted ? showNotification() : showError();
})();
OR
You can also use various push notifications API which can be configured using Javascript and easy to use.
3. https://pushy.me/docs/api/send-notifications (You can send notifications using .NET in this)
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly