Document Editor: How to Customize the Reconnecting Alert Message
Under rare conditions, the constant WebSocket connection may be interrupted, for example, if the Internet connection is lost for a very short period of time. This example shows how to customize the alert message that informs the user that TX Text Control is attempting to reconnect.

A constantly open WebSocket connection to the WebSocketHandler is required for the Document Editor. This connection is necessary for document rendering synchronization and true WYSIWYG rendering. If the connection is closed for any reason, TX Text Control will attempt to reconnect to the same instance using a unique connection identifier. Reasons for a lost connection can include a brief interruption, network problems, or routing issues.
When you create an instance of the Document Editor, you can specify the number of seconds that TX Text Control will attempt to reconnect.
@Html.TXTextControl().TextControl(settings => {
settings.ReconnectTimeout = 20;
}).Render()
Unsaved changes are not lost and the full document state is available when the connection is successfully restored. In case the connection is lost, the webSocketClosed event will fire with information about the reason.
TXTextControl.addEventListener("webSocketClosed", function(e) { console.log(e) });
TX Text Control will display a default alert message that informs the user that the connection is lost and that TX Text Control is attempting to reconnect.
We have seen reports of users not waiting to reconnect and hitting F5 to refresh the page. This will result in a full reload and the document will be lost after a full recycle. This will result in a full reload and the document will be lost after a full recycle.
let mutationObserver;
TXTextControl.addEventListener("textControlLoaded", function () {
TXTextControl.addEventListener("webSocketClosed", (e) => {
observeDisconnect("#txErrMsgDiv");
});
});
function observeDisconnect(selector) {
const el = document.querySelector(selector);
mutationObserver = new MutationObserver((mutationRecords, observer) => {
Array.from(document.querySelectorAll(selector)).forEach((element) => {
if (element.innerText.includes("Reconnecting")) {
element.innerHTML =
"<strong>Please wait!</strong> We are working on it!<br /><br /><div style='vertical-align: middle;' class='spinner-border' role='status'><span class='sr-only'></span></div>";
}
observer.disconnect();
});
}).observe(document.documentElement, {
childList: true,
subtree: true,
characterData: false,
});
}
The following screenshot shows the custom message with a wait icon to visualize that something is happening.
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
Add JavaScript to PDFs with TX Text Control in C# .NET: Time-Based Alerts…
In this article, we explore how to enrich PDF documents with JavaScript using TX Text Control in C# .NET. Read on to learn how to create time-based alerts that trigger actions based on specific…
Using the Document Editor in SPA Applications using the removeFromDom Method
This article shows how to use the removeFromDom method to remove the Document Editor from the DOM when it is no longer needed. This is useful when the Document Editor is used in a Single Page…
Observe When the Reporting Preview Tab is Active Using MutationObserver
This article shows how to observe when the Reporting Preview tab is active using MutationObserver. The Reporting Preview tab is a feature of the TX Text Control Document Editor that allows you to…
ASP.NETJavaScriptDocument Editor
Removing Empty Pages in TX Text Control with JavaScript
TX Text Control offers a C# solution for removing empty pages already. However, implementing this in JavaScript provides more flexibility for web environments. By using JavaScript methods to…
Document Editor: Useful JavaScript Functions for Tables
This article shows how to use JavaScript functions to manipulate tables in the Document Editor. It demonstrates how to set and get text in a table cell, and how to export a table to JSON.