Example of Adornments TextBox in ASP.NET MVC TextBox Control
This example demonstrates the adornment capabilities of the Syncfusion TextBox component. Adornments are custom elements that can be added by using the prependTemplate and appendTemplate properties of the textbox to provide additional functionality or visual cues. This feature allows for enhanced user interaction, such as a dropdown for prefixes or clickable icons to toggle password visibility or clear input.
.com
@Html.UiTextBox("prepend", null, new UiTextBoxOptions { Label = "Enter your Name", FloatLabelType = UiFloatLabelType.Auto, CssClass = "e-prepend-textbox", PrependTemplate = "#tbUser" })
@Html.UiTextBox("append", null, new UiTextBoxOptions { Label = "Password", FloatLabelType = UiFloatLabelType.Auto, Type = UiTextBoxType.Password, CssClass = "e-eye-icon", AppendTemplate = "#tbEye" })
@Html.UiTextBox("iconTextbox", null, new UiTextBoxOptions { Label = "Enter the Mail Address", FloatLabelType = UiFloatLabelType.Auto, CssClass = "e-icon-textbox", PrependTemplate = "#tbPeople", AppendTemplate = "#tbMail" })
<style>
.content-wrapper { width: 90%; margin: 0 auto; min-width: 185px; }
.content-wrapper .tb-row { display: flex; gap: 24px; padding: 12px 0; }
.content-wrapper .tb-row > * { flex: 1 1 0; min-width: 0; }
.content-wrapper .tb-title { padding: 15px 0 0; font-weight: 700; }
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.ador-textbox { width: 35%; margin: 5% auto; min-width: 250px; }
.ador-textbox .tb-row { margin: 7% 0; }
.ador-textbox .e-eye-icon .e-icons.e-eye, .ador-textbox .e-eye-icon .e-icons.e-eye-slash, .ador-textbox .e-icon-textbox .e-icons.e-trash { cursor: pointer; }
</style>
<template id="tbUser"><span class="e-icons e-user"></span><span class="ui-input-separator"></span></template>
<template id="tbEye"><span class="ui-input-separator"></span><span id="text-icon" class="e-icons e-eye"></span></template>
<template id="tbPeople"><span class="e-icons e-people"></span><span class="ui-input-separator"></span></template>
<template id="tbMail"><span>.com</span><span class="ui-input-separator"></span><span id="delete-text" class="e-icons e-trash"></span></template>
<div class="control-section">
<div class="content-wrapper ador-textbox">
<div class="tb-row">@Html.UiTextBox("prepend", null, new UiTextBoxOptions { Label = "Enter your Name", FloatLabelType = UiFloatLabelType.Auto, CssClass = "e-prepend-textbox", PrependTemplate = "#tbUser" })</div>
<div class="tb-row">@Html.UiTextBox("append", null, new UiTextBoxOptions { Label = "Password", FloatLabelType = UiFloatLabelType.Auto, Type = UiTextBoxType.Password, CssClass = "e-eye-icon", AppendTemplate = "#tbEye" })</div>
<div class="tb-row">@Html.UiTextBox("iconTextbox", null, new UiTextBoxOptions { Label = "Enter the Mail Address", FloatLabelType = UiFloatLabelType.Auto, CssClass = "e-icon-textbox", PrependTemplate = "#tbPeople", AppendTemplate = "#tbMail" })</div>
</div>
</div>
<script>
// Syncfusion: the eye icon shows or hides the password, the trash icon clears the mail address
document.addEventListener('click', function (e) {
var target = e.target.closest ? e.target.closest('#text-icon, #delete-text') : null;
if (!target) { return; }
if (target.id === 'text-icon') {
var password = document.getElementById('append');
var hidden = password.type === 'password';
password.type = hidden ? 'text' : 'password';
target.className = hidden ? 'e-icons e-eye-slash' : 'e-icons e-eye';
} else {
var mail = document.getElementById('iconTextbox');
mail.value = '';
mail.dispatchEvent(new Event('input', { bubbles: true }));
mail.focus();
}
});
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TextBoxController : Controller
{
// The page is Views/TextBox/Adornments.cshtml; it draws what ViewData holds.
public ActionResult Adornments()
{
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>
This sample demonstrates the adornment feature of the Syncfusion TextBox, showcasing how to integrate custom elements or icons at both the beginning and end of the input field
- The first textbox displays a prepended user icon representing the username.
- The second textbox features an appended eye icon, allowing users to toggle password visibility.
- The third textbox combines a prepended people icon with an appended ".com" text and a trash icon that clears the input when clicked.
These examples highlight the flexibility and enhanced user experience provided by TextBox adornments.