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.

MVC: Autosave and restore documents to and from the local browser storage

The following Javascript stores the document in an interval of 5 seconds and restores the document when the TX Text Control is initialized:

Loading...

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.

GitHub

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 for ASP.NET (trial sufficient)