Prevent change event in ASP.NET CORE Switch control

13 Dec 20241 minute to read

The BeforeChange event is triggered before the switch’s state is altered. This event provides an opportunity to intercept and potentially cancel the change action before it is applied. It allows for implementing conditional logic or validating the change prior to it being rendered on the UI.

<ejs-switch id="default" BeforeChange="BeforeChange"></ejs-switch>

<script>
    function BeforeChange(args) {
        // Set cancel to true to prevent the switch state change
        args.cancel = true;
    }
</script>
public ActionResult Default()
    {
            return View();
    }