Example of Events in ASP.NET MVC Slider Control
This sample demonstrates the events that have been triggered on the Slider operations with the help of event trace panel. Drag the thumb over the bar between min and max to know the event details.
@Html.UiSlider("minrange", new UiSliderOptions { Value = 30, Type = UiSliderType.MinRange, OnCreated = "onCreated_1", OnInput = "onChange", OnChange = "onChanged", Ticks = new UiSliderTicks { Placement = UiSliderPlacement.Both, LargeStep = 20, SmallStep = 5, ShowSmallTicks = true }, Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Always } })
@Html.UiButton(new UiButtonOptions { Id = "clear", Text = "Clear" })
<style>
.control-section .control-wrapper { width: 80%; margin: 0 auto; min-width: 185px; }
.sliderwrap { margin-top: 40px; }
.sliderwrap label, .slider-labeltext { display: block; padding-bottom: 14px; font-size: 13px; font-weight: 500; user-select: none; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
#EventLog span { display: block; font-size: 13px; }
</style>
<div class="control-section">
<div class="content-wrapper">
<div class="sliderwrap">
@Html.UiSlider("minrange", new UiSliderOptions { Value = 30, Type = UiSliderType.MinRange, OnCreated = "onCreated_1", OnInput = "onChange", OnChange = "onChanged", Ticks = new UiSliderTicks { Placement = UiSliderPlacement.Both, LargeStep = 20, SmallStep = 5, ShowSmallTicks = true }, Tooltip = new UiSliderTooltip { IsVisible = true, Placement = UiSliderPlacement.Before, ShowOn = UiSliderTooltipShowOn.Always } })
</div>
</div>
</div>
<div id="slider_event" class="demo-property-panel property-section" title="Event Trace">
<div class="eventarea" style="height: 245px; overflow: auto"><span class="EventLog" id="EventLog" style="word-break: normal;"></span></div>
<div class="evtbtn" style="padding-top: 10px">@Html.UiButton(new UiButtonOptions { Id = "clear", Text = "Clear" })</div>
</div>
<script>
// Syncfusion: the events of the slider are written to the event trace
var previous = 30;
function appendElement(html) {
var span = document.createElement('span');
span.innerHTML = html;
var log = document.getElementById('EventLog');
log.insertBefore(span, log.firstChild);
}
function onCreated_1() { appendElement('Slider control has been <b>created</b><hr>'); }
function onChange(value) { appendElement('Slider value is <b>changing</b> from ' + previous + ' to ' + value + '<hr>'); previous = value; }
var committedFrom = 30;
function onChanged(value) { appendElement('Slider value has been <b>changed</b> from ' + committedFrom + ' to ' + value + '<hr>'); committedFrom = value; }
document.getElementById('clear').addEventListener('click', function () { document.getElementById('EventLog').innerHTML = ''; });
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class RangeSliderController : Controller
{
// The page is Views/RangeSlider/Events.cshtml; it draws what ViewData holds.
public ActionResult Events()
{
return View();
}
}
}
@* Install once: Install-Package Lumen.UI.Mvc (or: dotnet add package Lumen.UI.Mvc) *@
@* Views/Web.config: <add namespace="Lumen.UI.Mvc" /> *@
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/Content/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@RenderSection("scripts", required: false)
</body>
Slider component triggers the event based on its actions. The events can be used as an extension point to perform custom operations.
In this demo, Slider performs following actions which can be traced by event trace panel:
- Created - Triggers when Slider is created.
- Change - Triggers when the Slider value is changed.
- Changed - Triggers when the Slider action is completed with change in Slider value.