Example of Toolbar in ASP.NET MVC Signature Control
This sample demonstrates the Signature control with toolbar items to illustrate the undo, redo, save with background, background color, stroke color, clear and disabled support of the Signature control.
@Html.UiSignature("signToolbar", new UiSignatureOptions { Height = "200px", MaxStrokeWidth = 2, OnChange = "toolbarChanged" })
<style>
.property-section .property-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.property-section .prop-input { width: 90px; 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; }
</style>
<div class="signature-toolbar" role="toolbar" aria-label="Signature tools">
<button type="button" class="btn btn-outline-secondary btn-sm" id="signUndo" disabled>Undo</button>
<button type="button" class="btn btn-outline-secondary btn-sm" id="signRedo" disabled>Redo</button>
<button type="button" class="btn btn-outline-secondary btn-sm" id="signClear" disabled>Clear</button>
<label>Pen
<select id="signColor" class="form-select form-select-sm">
<option value="#000000">Black</option>
<option value="#0f6cbd">Blue</option>
<option value="#d13438">Red</option>
</select>
</label>
<label>Width
<select id="signWidth" class="form-select form-select-sm">
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</label>
<label>Background
<select id="signBackground" class="form-select form-select-sm">
<option value="">None</option>
<option value="#fff4ce">Yellow</option>
<option value="#e3f0fd">Blue</option>
</select>
</label>
<button type="button" class="btn btn-primary btn-sm" id="signSave" disabled>Save</button>
<button type="button" class="btn btn-outline-secondary btn-sm" id="signDisable" aria-pressed="false">Disable</button>
</div>
@Html.UiSignature("signToolbar", new UiSignatureOptions { Height = "200px", MaxStrokeWidth = 2, OnChange = "toolbarChanged" })
<style>
.signature-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.signature-toolbar label { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-size: 13px; }
.signature-toolbar select { width: auto; }
</style>
<script>
// Syncfusion: the toolbar works the signature through its API: undo, redo, clear, the pen, the background, save and disabling
function pad() { return window.Lumen.get('signToolbar'); }
function byId(id) { return document.getElementById(id); }
function sync() {
var p = pad();
if (!p) { return; }
byId('signUndo').disabled = !p.canUndo();
byId('signRedo').disabled = !p.canRedo();
byId('signClear').disabled = p.isEmpty();
byId('signSave').disabled = p.isEmpty();
}
function toolbarChanged() { sync(); }
document.addEventListener('click', function (e) {
var p = pad();
if (!p || !e.target.id) { return; }
if (e.target.id === 'signUndo') { p.undo(); }
else if (e.target.id === 'signRedo') { p.redo(); }
else if (e.target.id === 'signClear') { p.clear(); }
else if (e.target.id === 'signSave') { p.save('png', 'demo-signature'); }
else if (e.target.id === 'signDisable') {
var off = p.isEnabled();
if (off) { p.disable(); } else { p.enable(); }
e.target.textContent = off ? 'Enable' : 'Disable';
e.target.setAttribute('aria-pressed', off ? 'true' : 'false');
}
else { return; }
sync();
});
document.addEventListener('change', function (e) {
var p = pad();
if (!p) { return; }
if (e.target.id === 'signColor') { p.setStrokeColor(e.target.value); }
else if (e.target.id === 'signWidth') { p.setMaxStrokeWidth(Number(e.target.value)); }
else if (e.target.id === 'signBackground') { p.setBackgroundColor(e.target.value || null); }
});
</script>
<script>
(function (window, document) {
'use strict';
// The toolbar of the signature-toolbar sample, on the pad's JavaScript API. The drawing itself is never logged.
function pad() { return window.Lumen.get('signToolbar'); }
function byId(id) { return document.getElementById(id); }
function sync() {
var p = pad();
if (!p) { return; }
byId('signUndo').disabled = !p.canUndo();
byId('signRedo').disabled = !p.canRedo();
byId('signClear').disabled = p.isEmpty();
byId('signSave').disabled = p.isEmpty();
}
window.SignatureToolbar = {
changed: function (args) {
sync();
if (window.InputSampleLog) { window.InputSampleLog('Signature: ' + args.actionName); }
}
};
document.addEventListener('click', function (e) {
var p = pad();
if (!p || !e.target.id) { return; }
if (e.target.id === 'signUndo') { p.undo(); }
else if (e.target.id === 'signRedo') { p.redo(); }
else if (e.target.id === 'signClear') { p.clear(); }
else if (e.target.id === 'signSave') { p.save('png', 'demo-signature'); }
else if (e.target.id === 'signDisable') {
var off = p.isEnabled();
if (off) { p.disable(); } else { p.enable(); }
e.target.textContent = off ? 'Enable' : 'Disable';
e.target.setAttribute('aria-pressed', off ? 'true' : 'false');
}
else { return; }
sync();
});
document.addEventListener('change', function (e) {
var p = pad();
if (!p) { return; }
if (e.target.id === 'signColor') { p.setStrokeColor(e.target.value); }
else if (e.target.id === 'signWidth') { p.setMaxStrokeWidth(Number(e.target.value)); }
else if (e.target.id === 'signBackground') { p.setBackgroundColor(e.target.value || null); }
});
})(window, document);
</script>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class SignatureController : Controller
{
// The page is Views/Signature/Toolbar.cshtml; it draws what ViewData holds.
public ActionResult Toolbar()
{
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>
The Signature control supports undo, redo, background color, stroke color, save, save with background, clear, and disabled functionalities.
In this sample, each toolbar item illustrates the Signature control functionalities, which are listed below.
Use Undo button or Ctrl + Z key to revert your signature.
Use the Redo button or Ctrl + Y key to remake your reverted signature.
Use the Save button or Ctrl + S key to store your signature as an image file.
Stroke color picker is used to apply the stroke color to the Signature control.
Background color picker is used to apply the background color to the Signature control.
Use Stroke Width drop-down list values to change the signature stroke width.
Use the Clear button to clear the signature.
Check the Disabled checkbox to disable the Signature control.