MVC: Autosave and Restore Documents to and from the Local Browser Storage
Modern HTML5-based web browsers support persistent data storage with an enhanced capacity up to 50MB local storage. It is possible to store data persistently or session based. This sample shows how use the local storage to autosave documents and how to restore documents when the page is refreshed or reloaded. The following Javascript stores the document in an interval of 5 seconds and restores the document when the TX Text Control is initialized: When the Web.TextControl is loaded…

Modern HTML5-based web browsers support persistent data storage with an enhanced capacity up to 50MB local storage. It is possible to store data persistently or session based.
This sample shows how use the local storage to autosave documents and how to restore documents when the page is refreshed or reloaded.

The following Javascript stores the document in an interval of 5 seconds and restores the document when the TX Text Control is initialized:
TXTextControl.addEventListener("ribbonTabsLoaded", function (e) {
restoreDocument();
var intervalAutoSave = setInterval(autoSaveDocument, 5000);
});
function autoSaveDocument() {
TXTextControl.saveDocument(TXTextControl.streamType.InternalUnicodeFormat, function (e) {
localStorage.document = e.data;
});
}
function restoreDocument() {
if (localStorage["document"]) {
TXTextControl.loadDocument(
TXTextControl.streamType.InternalUnicodeFormat,
localStorage.document);
$(".info").css("display", "inline-block");
}
}
When the Web.TextControl is loaded completely, the ribbonTabsLoaded event is fired. In this event, the interval is created and a previously stored document is loaded.
The function autoSaveDocument uses the saveDocument method to store the document in the local storage variable document.
The function restoreDocument is loading the stored document back into TX Text Control using loadDocument. Finally, a green info bar is displayed to visualize that a document has been restored.
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
Happy New Year, everybody! In the last blog entry, we showed how to replace the file menu with an MS Word-style backstage menu. This project shows how to load documents from a partial view in the…
MVC: Replace the File Menu with a Backstage View Menu
Microsoft Word provides a very smart way to manage documents and related data such as metadata and personal information in a separate view: The backstage view. The ribbon bar contains commands for…
MVC: Replace the Ribbon Table Menu with a Quick Insert Table Drop-down
MS Word provides a quick insert table drop-down to insert tables into the document. This sample shows how to replace the insert table button with such a table insert drop-down. The replacement and…
MVC: Arrange a Docked Web.TextControl with a Custom Bar at the Top
Consider the following task: The Web.TextControl should be arranged under a custom bar that is located at the top of the page like in the following screenshot: Objects such as DIV elements doesn't…
MVC: Loading and Saving Documents Through Controller HttpPost Methods
With the release of TX Text Control X13, we released an MVC version of TXTextControl.Web that is available through NuGet. This sample project shows how to load and save documents using controller…