Document Editor: JavaScript Object Availability and Order of Events
The online document editor, available for MVC and Angular, provides a JavaScript API to manipulate the document and the style and behavior of the editor. This article explains the order of events that are required to ensure the availability of the TXTextControl object and provides a general overview of available events.

The document editor can be programmatically accessed using the JavaScript object TXTextControl. When using ASP.NET MVC or Web Forms, this object exists directly after loading the page and can be used right away from within JavaScript. For example, in the following view code, the event textControlChanged is directly added to TXTextControl on executing the page.
@using TXTextControl.Web.MVC
@Html.TXTextControl().TextControl().Render()
@section Scripts {
<script type="text/javascript">
TXTextControl.addEventListener("textControlChanged", function () {
console.log("textControlChanged");
});
</script>
}
Angular Only: txDocumentEditorLoaded
When using Angular, the object TXTextControl is dynamically created and therefore accessible at a later time. For this purpose, a global event on the document element is available. After this event is triggered, the TXTextControl object is available.
The following code shows how to attach an event to TXTextControl within the txDocumentEditorLoaded event handler:
document.addEventListener("txDocumentEditorLoaded", function () {
TXTextControl.addEventListener("textControlChanged", function () {
console.log("textControlChanged");
});
});
Diagram: Initialization Events
The following diagram shows the chain of events that are fired on creating a new instance of the document editor.

Event order diagram: Asynchronous events on initializing the editor.
The events textControlLoaded, documentLoaded and ribbonTabsLoaded are asynchronous and the order might vary depending on the loading time and file size for loaded documents.
Manipulating the Content
The content of the document can be manipulated after the textControlLoaded event is fired. The following code will not work as the Text Control is not ready to accept changes on the document:
@using TXTextControl.Web.MVC
@Html.TXTextControl().TextControl().Render()
@section Scripts {
<script type="text/javascript">
TXTextControl.selection.setText("Text Control rocks!");
</script>
}
In order to manipulate the content on creating a new instance of the editor, the code must be inside (or after) the textControlLoaded event:
@using TXTextControl.Web.MVC
@Html.TXTextControl().TextControl().Render()
@section Scripts {
<script type="text/javascript">
TXTextControl.addEventListener("textControlLoaded", function () {
TXTextControl.selection.setText("Text Control rocks!");
});
</script>
}
Manipulating a Document
In case a document is loaded on creating an instance of the document editor, the content can be manipulated after the documentLoaded event is triggered:
@using TXTextControl.Web.MVC
@Html.TXTextControl().TextControl().LoadText(
"Hi there! ", TXTextControl.Web.StringStreamType.PlainText).Render()
@section Scripts {
<script type="text/javascript">
TXTextControl.addEventListener("documentLoaded", function () {
TXTextControl.select(-1, 0);
TXTextControl.selection.setText("Text Control rocks!");
});
</script>
}
Changing the Ribbon
The last event in this chain is the ribbonTabsLoaded event that is triggered after the complete ribbon DOM is available for manipulation. The following code shows how to remove the Clipboard ribbon group of the Home ribbon tab:
TXTextControl.addEventListener("ribbonTabsLoaded", function () {
document.getElementById("ribbonGroupClipboard").remove();
});
After all of these 3 events have been triggered, all JavaScript API calls can be made to manipulate the content, document and the editor DOM.
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
JavaScript: Avoid Flickering and Visual Updates by Grouping Undo Steps
The JavaScript API can be used to group several steps into one undo action that can be undone with a single undo call. Additionally, those groups are visually updated at once to avoid screen…
DS Server or TX Text Control? Different Deployment Scenarios
The Text Control document processing technology can be deployed in various ways using different products for different applications. This overview explains the differences and deployment strategies.
Using TX Text Control .NET Server in Blazor Server Apps
The TX Text Control document editor and the server-side non-UI component ServerTextControl can be used in Blazor Server Apps. This article shows how to save documents to the server and how to…
Using DS Server with Blazor
This sample and article shows how to integrate the DS Server DocumentEditor using JavaScript into an ASP.NET Blazor application. Blazor allows you create interactive web applications using C#.
Track Changes: Show 'Original' and 'No Markup'
The redlining feature is very helpful when working on the same document with multiple authors specifically with legal or healthcare documents where changes need to be tracked and safely logged.…