This blog post contains outdated information.
The cited code snippets may be workarounds, and be part of the official API in the meantime.
ASP.NET MVC: Implementing a Simplistic, Custom Button Bar
This ASP.NET MVC sample replaces the Web.TextControl ribbon bar with a custom button bar built in HTML, CSS, and JavaScript. Toggle buttons apply formatting commands like bold, while the inputFormatReceived event synchronizes each button state with the text format at the caret position.

For some applications, the fully-featured ribbon bar might be too overloaded with features or the ribbon concept is not required in a project. Programmatically, all ribbon tabs, groups and buttons can be removed or modified. But this sample shows how remove the ribbon bar completely and to implement your own, custom button bar with simple toggle buttons.

The whole implementation is done using pure HTML, CSS and JavaScript. The following HTML represents the custom ribbon bar:
<div class="customButtonBar">
<div class="ck-button">
<label>
<input id="bold" type="checkbox"><span><strong>Bold</strong></span>
</label>
</div>
<div class="ck-button">
<label>
<input id="italic" type="checkbox"><span><em>Italic</em></span>
</label>
</div>
<select id="fontSize">
<option value="200">10</option>
<option value="240">12</option>
<option value="320">16</option>
<option value="400">20</option>
</select>
</div>
The following JavaScript code is used to attach a click event to the Bold button. Using a command, the TXTextControl.InputFormatProperty.Bold is set on Text Control.
// click handler for the "Bold" button
$("#bold").click(function () {
// send command to enable/disable bold for current selection
if ($("#bold").prop("checked"))
TXTextControl.sendCommand(TXTextControl.Command.InputFormat,
TXTextControl.InputFormatProperty.Bold, 1);
else
TXTextControl.sendCommand(TXTextControl.Command.InputFormat,
TXTextControl.InputFormatProperty.Bold, 0);
TXTextControl.focus();
});
In order to update the state of the button based on the current input position, the inputFormatReceived event is used. This event is triggered, if the format at the current position has been changed (or the input position has been changed to another position with a different format):
document.addEventListener("inputFormatReceived", function (e) {
var msg = e.detail;
// process "Bold"
if (msg.hasOwnProperty("Bold"))
inputFormatChanged(TXTextControl.InputFormatProperty.Bold, msg.Bold);
});
In the event handler itself, the returned id defines the input format property. Using a switch statement, all different cases are handled. If the text at the current input position is formatted with bold, the value parameter is true and the button status is updated accordingly:
// process received format options
function inputFormatChanged(id, value, stringValue) {
switch (id) {
// handle the "Bold" button
case TXTextControl.InputFormatProperty.Bold:
if (value == true)
$("#bold").prop("checked", true);
else
$("#bold").prop("checked", false);
break;
}
}
Download the sample from GitHub and test it on your own.
![]()
Download and Fork This Sample on GitHub
We proudly host our sample code on github.com/TextControl.
Please fork and contribute.
Requirements for this sample
- Visual Studio 2015 or better
- TX Text Control .NET Server (trial sufficient)
ASP.NET
Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.
- Angular
- Blazor
- React
- JavaScript
- ASP.NET MVC, ASP.NET Core, and WebForms
Related Posts
ASP.NET MVC: Adding Protected Sections to Documents
SubTextParts in TX Text Control mark document regions as non-editable in Web.TextControl. An MVC controller method converts selected text into a SubTextPart using ServerTextControl, and…
ASP.NETReportingElectronic Signature
ASP.NET: Adding Electronic Signatures to Documents
An ASP.NET MVC sample demonstrates electronic signatures using an HTML5 canvas-based JavaScript signature pad. The captured signature image is sent to a controller action, which merges it into a…
HTML5: Display and Handle FormCheckBox Fields
MS Word FormCheckBox fields render in Web.TextControl by iterating ApplicationFields server-side and displaying Unicode checked or unchecked characters. The TextFieldClicked JavaScript event…
Creating Your First ASP.NET Reporting Application
The MailMerge and ServerTextControl components of TX Text Control .NET Server for ASP.NET enable server-side reporting in Web Forms. A template.docx merges with XML data via a button click…
Automatically Reconnect to the Server and Recover the Document
When a WebSocket connection drops, the TX Text Control editor automatically reconnects and recovers the document using browser local storage. The implementation saves document state client-side…
