Time out in Toast Control
3 May 20245 minutes to read
The toast can be expired based on the TimeOut
property. The toast can live till the time out reaches without user interaction, a time out value is considered as a millisecond.
-
The
TimeOut
delay can be visually represented usingProgress Bar
. -
The
ExtendedTimeOut
property determines how long the toast should be displayed after a user hovers over it.
NOTE
You can terminate the process by using the
ShowCloseButton
property for destroying the toast at any time.
<div style="width:400px; margin:0 auto;">
<div class="e-float-input"><input class="e-input" id="toast_input_index" required="" value="0"><span class="e-float-line"></span><label class="e-float-text">Enter timeOut</label></div>
@Html.EJS().Toast("element").Position(p => p.X("Right").Y("Bottom")).Width("300").Height("150").Buttons(item =>
{
item.ModelValue(ViewBag.ToastButtons1).Add();
item.ModelValue(ViewBag.ToastButtons2).Add();
}).ContentTemplate(@<div>
<p>
<img alt="Laura" class="toast-img" src="https://ej2.syncfusion.com/demos/src/toast/resource/laura.png" />
<span class="name">Anjolie Stokes</span>
</p>
<div class="content">
<p>Thanks for update!</p>
</div>
</div>).Render()
<div class="row">
@Html.EJS().Button("show_toast").Content("Show Toast").CssClass("e-btn").Render()
</div>
</div>
<script type="text/javascript">
setTimeout(
() => {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.target = document.body;
toastObj.show();
}, 1000);
document.getElementById("show_toast").addEventListener('click', function () {
var toastObj = document.getElementById('element').ej2_instances[0];
var value = parseInt(document.getElementById('toast_input_index').value)
toastObj.show({ timeOut: value });
});
</script>
<style>
.toast-img {
width: 40px;
height: 40px;
}
.name {
padding-left: 20px;
font-size: 17px;
font-weight: 500;
}
.content {
padding-left: 60px;
font-size: 12px;
}
</style>
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.ToastButtons1 = new DefaultButtonModel() { content = "Ignore" };
ViewBag.ToastButtons2 = new DefaultButtonModel() { content = "reply" };
return View();
}
public class DefaultButtonModel
{
public string content { get; set; }
}
}
Static toast
You can prevent auto hiding in a toast as visible like static by setting zero (0
) value in the TimeOut
Property.
<div class="control-section" style="width:400px;margin:0 auto;">
@Html.EJS().Toast("element").Title("Matt sent you a friend request").Content("You have a new friend request yet to accept").TimeOut(0).ShowCloseButton(true).Position(p => p.X("Right")).Render()
@Html.EJS().Button("show_toast").Content("Show Toast").CssClass("e-btn").Render()
</div>
<script type="text/javascript">
setTimeout(
() => {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.target = document.body;
toastObj.show();
}, 1000);
document.getElementById("show_toast").addEventListener('click', function () {
var toastObj = document.getElementById('element').ej2_instances[0];
toastObj.show();
});
</script>
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}