Example of API in ASP.NET MVC TextArea Control
This example demonstrates the api functionalities of the textarea control. You can customize the appearance and behaviour of textarea component by choosing the corresponding option from the property panel.
Rows
Columns
Enable
Read only
MaxLength
Value
Show clear icon
@Html.UiTextArea("api", null, new UiTextAreaOptions { Label = "Enter your comments", FloatLabelType = UiFloatLabelType.Auto, Rows = 2, ShowClearButton = true })
@Html.UiNumericTextBox("rows", new UiNumericTextBoxOptions { Value = 2, Min = 1, Max = 10, Step = 1, Format = "N0", Width = "100px", OnChange = "rowHandler" })
@Html.UiNumericTextBox("cols", new UiNumericTextBoxOptions { Value = 20, Min = 5, Max = 40, Step = 1, Format = "N0", Width = "100px", OnChange = "columnHandler" })
@Html.UiCheckBox("enabled", true, new UiCheckBoxOptions { Id = "enabled", OnChange = "enabledHandler" })
@Html.UiCheckBox("readonly", false, new UiCheckBoxOptions { Id = "readonly", OnChange = "readonlyHandler" })
@Html.UiNumericTextBox("maxlength", new UiNumericTextBoxOptions { Value = -1, Step = 1, Format = "N0", Width = "100px", OnChange = "maxLengthHandler" })
@Html.UiCheckBox("clearicon", false, new UiCheckBoxOptions { Id = "clearicon", OnChange = "clearIconHandler" })
<style>
.content-wrapper { width: 90%; margin: 0 auto; min-width: 185px; }
.content-wrapper .ta-row { padding: 12px 0; }
.content-wrapper .ta-cols { display: flex; gap: 24px; }
.content-wrapper .ta-cols > * { flex: 1 1 0; min-width: 0; }
.content-wrapper .ta-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; }
.property-section .prop-input { width: 130px; padding: 4px 6px; border: 1px solid var(--ui-input-border); border-radius: var(--ui-radius); background: var(--ui-surface); color: var(--ui-text); font: inherit; }
#textarea-api .ta-row { margin: 30px 0; }
</style>
<div id="textarea-api" class="control-section api">
<div class="content-wrapper">
<div class="ta-row">
@Html.UiTextArea("api", null, new UiTextAreaOptions { Label = "Enter your comments", FloatLabelType = UiFloatLabelType.Auto, Rows = 2, ShowClearButton = true })
</div>
</div>
</div>
<div class="demo-property-panel property-section api-property" title="Properties">
<div class="property-row"><span>Rows</span> @Html.UiNumericTextBox("rows", new UiNumericTextBoxOptions { Value = 2, Min = 1, Max = 10, Step = 1, Format = "N0", Width = "100px", OnChange = "rowHandler" })</div>
<div class="property-row"><span>Columns</span> @Html.UiNumericTextBox("cols", new UiNumericTextBoxOptions { Value = 20, Min = 5, Max = 40, Step = 1, Format = "N0", Width = "100px", OnChange = "columnHandler" })</div>
<div class="property-row"><span>Enable</span> @Html.UiCheckBox("enabled", true, new UiCheckBoxOptions { Id = "enabled", OnChange = "enabledHandler" })</div>
<div class="property-row"><span>Read only</span> @Html.UiCheckBox("readonly", false, new UiCheckBoxOptions { Id = "readonly", OnChange = "readonlyHandler" })</div>
<div class="property-row"><span>MaxLength</span> @Html.UiNumericTextBox("maxlength", new UiNumericTextBoxOptions { Value = -1, Step = 1, Format = "N0", Width = "100px", OnChange = "maxLengthHandler" })</div>
<div class="property-row"><span>Value</span> <input id="value" type="text" placeholder="Enter a value" class="prop-input" /></div>
<div class="property-row"><span>Show clear icon</span> @Html.UiCheckBox("clearicon", false, new UiCheckBoxOptions { Id = "clearicon", OnChange = "clearIconHandler" })</div>
</div>
<script>
// Syncfusion: the property panel sets the rows, the columns, the states, the maximum length, the value and the clear icon of the textarea
function area() { return window.Lumen.get('api'); }
function enabledHandler(checked) { area()[checked ? 'enable' : 'disable'](); }
function readonlyHandler(checked) { area().setReadOnly(checked); }
function maxLengthHandler(value) { area().setMaxLength(value); }
function rowHandler(value) { area().setRows(value); }
function columnHandler(value) { area().setCols(value); }
function clearIconHandler(checked) { area().setShowClearButton(checked); }
document.addEventListener('input', function (e) { if (e.target.id === 'value') { area().setValue(e.target.value); } });
// the clear icon is off until the panel turns it on
window.addEventListener('load', function () { area().setShowClearButton(false); });
</script>
<script>
(function (window, document) {
'use strict';
document.querySelector('.input-actions').addEventListener('click', function (event) {
var action = event.target.getAttribute('data-input-action');
var control = window.Lumen.get('inputApi');
if (!action || !control) { return; }
if (action === 'set') { control.setValue('Demo notes'); }
else if (action === 'state') { window.InputSampleLog('Text length: ' + control.getValue().length); return; }
else if (action === 'enabled') { control[control.isEnabled() ? 'disable' : 'enable'](); }
else if (action === 'focus') { control.focus(); }
window.InputSampleLog('API action: ' + action);
});
})(window, document);
</script>
using System;
using System.Collections.Generic;
using System.IO;
using System.Web;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class TextAreaController : Controller
{
// The page is Views/TextArea/Api.cshtml; it draws what ViewData holds.
public ActionResult Api()
{
return View();
}
private ActionResult Show(string method)
{
InputSample sample = (InputSample)ViewBag.InputSample;
// A sample keeps its data in a Prepare<Page> method (InputsDemoController.Samples.cs); it puts what the page reads in ViewData.
string page = sample.Source.Substring(sample.Source.LastIndexOf('_') + 1);
System.Reflection.MethodInfo prepare = GetType().GetMethod(method + page, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (prepare != null) { prepare.Invoke(this, null); }
return View("PreparedSample", ViewData.Model);
}
}
}
@* 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>
@* Inputss with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
The TextArea has the options to customize the appearance and behaviour of the component dynamically by updating the following properties:
- Change the number of rows and columns of textarea by updating "Rows" and "Columns" options.
- To make the textarea read-only, check the "read-only" option.
- Disable the textarea by unchecking the "enabled" option.
- Set the maximum length of characters that can be entered in textarea by customizing the "MaxLength" option.
- Update the value of textarea by entering text in "Value" option.
- To make the clear button visible, check the "Show clear icon" option..