2

I am having an web application in ASP.NET which allows users to enter data and the data will be stored in the remote SQL Table. I want to implement a functionality that will enable uses even to post the data when they are offline.

When the users are offline they can enter data and save them and it needs to be stored in the cache. However when the system gets connected to the internet, i need to retrieve the data saved by the user which is in cache and save it to my remote SQL table.

Can anyone let me know how can I implement this?

From this post `Build an ASP.Net web app with offline functionality its clear we can have offline functionality that will store the data in the application cache. However I also want to save the values entered by the user to my database. I want to know how to do that part.

Community
  • 1
  • 1
Karthik Venkatraman
  • 1,619
  • 4
  • 25
  • 55
  • 1
    Possible duplicate of [Build an ASP.Net web app with offline functionality](http://stackoverflow.com/questions/18102002/build-an-asp-net-web-app-with-offline-functionality) – Thomas Jun 10 '16 at 06:46
  • How do the users enter the data off line in an ASP.net application? Just viewing a page reqires a connection to webserver. – Jon P Jun 10 '16 at 06:47
  • @JonP Hi, When the system is connected to the internet for the first time, it stores all the data from my server to client system using the Application Cache and Web Storage technique. After that even when the user is offline, he can view the web site as its already stored. – Karthik Venkatraman Jun 10 '16 at 06:54

1 Answers1

3

This article describes a solution using Application Cache, Web Storage and ASP.NET MVC - codemag

The article does a great job of explaining things but for the sake of a complete answer - basically you need an application manifest file e.g.

CACHE MANIFEST
# version 1

CACHE:
/home.htm
/images/logo.png
/styles/global.css
/script.js

FALLBACK:
/events.aspx /events.htm

NETWORK:
/customer/list

Then you reference this file in your html e.g.

<html manifest="manifest.appcache">

Next you need a way to tell whether there is a connection or not and also when the connection status changes. Fortunately this is easy using:

window.navigator.onLine //to detect the status

//Browser raises this event when online is detected
window.addEventListener("online", function (e) {
    //save to server
}, true);

//Browser raises this event when offline
window.addEventListener("offline", function (e) {
}, true);

When saving offline you can save to localStorage e.g.

 localStorage.setItem(JSON.stringify(data));

Then it should be a simple Ajax call to to save the data when you detect that the connection is online again.

majita
  • 1,278
  • 14
  • 24
  • Seems to be a good starting point !!! – Thomas Jun 10 '16 at 06:44
  • Hi, This will store the data from my server to the client system. However I want to upload the data from the client system to my sql server. I want to know that part. – Karthik Venkatraman Jun 10 '16 at 06:52
  • Hi Karthik, when you detect that browser is online again use ajax to post previously saved localStorage data to server. I have edited answer to include this step – majita Jun 10 '16 at 07:36
  • cant we do this in c# instead of ajax? – Karthik Venkatraman Jun 10 '16 at 07:47
  • not that I am aware of. The server side part where you actually save to database you can use c# but you have to somehow get the data back to the server and the best way I can think of to do this is to make an ajax call. – majita Jun 10 '16 at 08:10