The JavaScript API covers the most typical tasks such as inserting merge fields and setting edit modes of TX Text Control. Sometimes, more complex tasks require the usage of a server-side TXTextControl.ServerTextControl object to manipulate the document.

In order to insert a more complex document element into the text, the document can be saved locally and send to a server-side endpoint like a Web API method. After the document has been changed server-side, it can be returned and loaded using JavaScript. If the complete document is loaded and not only the selection is replaced, it is required to restore the old scroll location. By default, after a loading process, the TX Text Control scrolls to top left automatically.

Loading...

The event textViewLocationChanged returns the current scroll location which is stored in the variable scrollLocation. The dummy function insertComplexElement stores the current scroll location in the variable freezedScrollLocation before it is sending the document to the server. After the document has been retrieved from the server, it is loaded and the scroll location is restored using the command ScrollDelta. In order to use this code, it is required to turn on the hidden command interface which is done using the enableCommands method.

How to load and save documents from and to the MVC controller can be found in this article:

MVC: Loading and Saving Documents Through Controller HttpPost Methods