Search results

Play an audio before open the toast in ASP.NET MVC 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;">
    @Html.EJS().Toast("element").Title("Matt sent you a friend request").Position(p => p.X("Right").Y("Bottom")).Content("You have a new friend request yet to accept").BeforeOpen("onBeforeOpen").Render()
    <div class="row">
        @Html.EJS().Button("show_toast").Content("Show Toast").CssClass("e-btn").Render()
<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();