Search results

Play an audio before open the toast in ASP.NET Core Toast control

The following sample demonstrates how to play an audio in background while opening the toast by including audio play codes into the beforeOpen event function.

To stop the audio after displaying the toast, use the open event in toast. For further customization, check the Toast Events APIs.

<div class="control-section" style="width:400px;margin:0 auto;">
    <ejs-toast id="element" title="Matt sent you a friend request" content="You have a new friend request yet to accept" beforeOpen="onBeforeOpen">
        <e-toast-position X="Right" Y="Bottom"></e-toast-position>
    <div class="row">
        <ejs-button id="show_toast" content="Show Toast" cssClass="e-btn"></ejs-button>
<script type="text/javascript">
        () => {
            var toastObj = document.getElementById('element').ej2_instances[0];
   = document.body;
        }, 1000);
    function onBeforeOpen(e) {
        let audio = new Audio('');;
    document.getElementById("show_toast").addEventListener('click', function () {
        var toastObj = document.getElementById('element').ej2_instances[0];;
public class HomeController : Controller

    public ActionResult Index()
        return View();