Web.TextControl: JQueryUI Alert Boxes and Javascript Events
Web.TextControl X12 ribbon items can be customized via CSS to hide elements and through JavaScript event listeners to intercept clicks with event bubbling control. The Open File dialog can be manipulated to preset file type selections by polling for DOM elements once loaded.

The online demo Simple implements some features based on the newly available API of Web.TextControl. It shows 3 typical tasks:
- Remove the Save As... menu item
- Attach event handlers to ribbon items, stop the event bubbling and show alert boxes
- Manipulate the out-of-the-box jQueryUI dialog boxes
Removing Ribbon Items
The first task can be easily realized using CSS:
<style>
#fileMnuItemSaveAs {
display: none !important;
}
</style>
Each element including ribbon tabs, groups and items have specific CSS class names which can be customized. In this case, the display property is set to none to hide the element completely.
Attaching Events and Handle Event Bubbling
To achieve the second task, we need to trap an event from Web.TextControl that is raised when the ribbon bar is completely loaded. Otherwise, elements of the ribbon bar cannot be manipulated in the DOM.
TXTextControl.addEventListener("ribbonTabsLoaded", function (e) {
attachEvents();
});
In the function attachEvents, click events are attached to the menu item Open and Save. When clicking Open, the function waitForFileOpenDialog is called.
function attachEvents() {
// attach click event handler to \'load\' button
document.getElementById("fileMnuItemOpen").addEventListener("click",
function (e) {
waitForFileOpenDialog();
});
// [...]
}
Manipulating JQueryUI Dialog Boxes
The function waitForFileOpenDialog is a recursive function that is basically waiting (looping) until the DOM element txOFDSelFileType exists. This element is the File Type selection drop down box in the Open File dialog box from Web.TextControl:
The idea is to wait until the element is available in order to pre-select another file type (All Files (*.*)). The function reorderListView sets the selectedIndex property to 0 in order to raise a change event to update the file list:
// wait until the file open dialog is opened
function waitForFileOpenDialog() {
var checkExist = setInterval(function () {
if (document.getElementById("txOFDSelFileType") != null) {
clearInterval(checkExist);
reorderListView()
}
}, 100);
}
// select \'All Files\' and fire the Change event to update the file list
function reorderListView() {
setTimeout(function () {
document.getElementById("txOFDSelFileType").selectedIndex = 0;
fireEvent(document.getElementById("txOFDSelFileType"), "change");
}, 300);
}
When clicking Save, a jQueryUI alert message dialog is shown and the event bubbling is canceled.
The newly attached event is raised before it is bubbled to Web.TextControl. This allows you to cancel the default functionality of a ribbon item in order to add your own action such as opening an alert message box:
// this function attaches events after the ribbon has been loaded completely
function attachEvents() {
// [...]
// attach click event handler to \'save\' button, show an alert
// message box and stop the bubbling of the click event to Web.TextControl
document.getElementById("fileMnuItemSave").addEventListener("click",
function (e) {
jQueryAlert("TX Text Control", "Alert message");
e.cancelBubble = true;
});
}
Web.TextControl uses jQueryUI for all dialogs including message boxes. In order to use the above code, jQuery and jQueryUI must be referenced:
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>
<script
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
</script>
If no other jQueryUI CSS is defined, the TX Text Control dialog style will be used automatically:
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 2012 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
MVC: Loading Files from the Backstage Menu
An MVC partial backstage view lists available files from a directory using a simple document model. When a user clicks a file, JavaScript sends an AJAX request to an HttpPost controller method…
MVC: Replace the File Menu with a Backstage View Menu
Replace the Web.TextControl File menu with a full-page backstage view using JavaScript and CSS. The tutorial disables the default FILE ribbon handler, renders a vertical navigation panel with…
MVC: Replace the Ribbon Table Menu with a Quick Insert Table Drop-down
Replace the default Web.TextControl ribbon table button with a grid-based quick insert dropdown using JavaScript. The tutorial renders a visual row-and-column picker, sends the selected dimensions…
MVC: Arrange a Docked Web.TextControl with a Custom Bar at the Top
Position a docked Web.TextControl below a custom toolbar bar in an MVC view by using CSS and JavaScript to offset the editor. The tutorial wraps the control in a DIV, sets absolute positioning…
MVC: Autosave and Restore Documents to and from the Local Browser Storage
Web.TextControl documents are autosaved to browser localStorage at five-second intervals using the JavaScript saveDocument method. On page reload, the ribbonTabsLoaded event checks for stored…
