Search results

Prevent toast close with mobile swipe in ASP.NET Core Toast control

14 Apr 2021 / 1 minute to read

You can prevent the toast close with mobile swipe action by setting beforeClose argument cancel value to true while argument type is swipe. The following code shows how to prevent toast close with mobile swipe.

The following sample demonstrates preventing toast close with mobile swipe element displaying with custom code blocks.

tagHelper
controller.cs
Copied to clipboard
<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" beforeClose="beforeClose"></ejs-toast>
    <ejs-button id="button" content="Show Toast" cssClass="e-btn"></ejs-button>
</div>
<script type="text/javascript">
    setTimeout(
        () => {
            var toastObj = document.getElementById('element').ej2_instances[0];
            toastObj.target = document.body;
            toastObj.show();
        }, 1000);
    document.getElementById("button").addEventListener('click', function () {
        var toastObj = document.getElementById('element').ej2_instances[0];
        toastObj.show();
    });
    function beforeClose(args: ToastBeforeCloseArgs){
        if (args.type === "swipe") {
            args.cancel = true;
        }
    }
</script>
Copied to clipboard
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View();
    }
}