[c4mvc] Update DB when browser is closed

12 views
Skip to first unread message

nomad

unread,
Apr 16, 2010, 3:50:12 PM4/16/10
to Community for ASP.NET MVC
Hi,

I have a website written in MVC 1.0 which has several pages of
quesitons for users to fill in. After every page a blob of xml
containing their answered questions up to that point is saved to the
DB, so that if they leave, close the browser or their session ends it
has their partial answered question set saved. I would prefer to not
hit the DB after every page so was wondering if there is a way that I
can detect if the user closes the browser, or moves to another site,
so I can then do one update to the DB of the xml blob of their
currently answered question set.

Appreciate any help on this.

--
You received this message because you are subscribed to the "Community for ASP.NET MVC" group.

To post to this group, send email to c4...@googlegroups.com

To unsubscribe from this group, send email to
c4mvc+un...@googlegroups.com
For more options, visit this group at
http://CommunityForMvc.Net

Chi Chan

unread,
Apr 16, 2010, 4:30:16 PM4/16/10
to Community for ASP.NET MVC
Hi there,

My best guess is that you can do it with Javascript just like gmail
does. I think they do this:

1) If you try to close the tab/browser when your content is still
dirty, it will pop a message box asking for confirmation. This is prop
done with something like the onbeforeunload event

http://social.msdn.microsoft.com/Forums/en-US/iewebdevelopment/thread/88b39eab-cf00-49cf-a30e-5949f1978ea5

2) By using a timer, save the dirty content every now and then. This
is prop done with the setTimeout event

http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/



IMO, if your data is not important, I guess you can save it on the
client's cookie if you want. But at the end of the day, you gotta save
the data SOMEWHERE.

Hope it helps,

Chi

djy...@gmail.com

unread,
Apr 18, 2010, 9:08:58 PM4/18/10
to c4...@googlegroups.com

Use the document.unload function to postback?

Tuna Toksoz

unread,
Apr 18, 2010, 9:22:25 PM4/18/10
to c4...@googlegroups.com
May not work.  What if browser "crashes"?


Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike

djy...@gmail.com

unread,
Apr 19, 2010, 9:44:41 PM4/19/10
to c4...@googlegroups.com
Or when the browser is opened,every several second post to server to update the status,and add a sql server agen,every several second execute,check the status ,if out the timespan,change it.

nomad

unread,
Apr 20, 2010, 2:25:42 PM4/20/10
to Community for ASP.NET MVC
I think I'll look into Chi's recommendaiton.

Thanks everyone for replying, is much appreciated.

Paul Roe

unread,
Apr 18, 2010, 9:38:35 PM4/18/10
to c4...@googlegroups.com
You'd have to setup some javascript that fires off a message to your server every x seconds and acts like a pulse. If you "loose the pulse" then you'd write their session to the database.

Liam Slater

unread,
Apr 19, 2010, 6:48:24 AM4/19/10
to c4...@googlegroups.com

How about a long running asynchronous process, each page adds its data to that and save to the db after either the last page or a set timeout, if it crashes then the timeout forces a save

On 19 Apr 2010 02:22, "Tuna Toksoz" <teh...@gmail.com> wrote:

May not work.  What if browser "crashes"?


Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike






On Mon, Apr 19, 2010 at 4:08 AM, <djy...@gmail.com> wrote:
>

> Use the document.unload function...

George Mauer

unread,
Apr 23, 2010, 8:47:42 AM4/23/10
to c4...@googlegroups.com

Why save to the db? Save to cookies continuously until they finish the form

On Apr 23, 2010 5:38 AM, "Paul Roe" <paul...@gmail.com> wrote:

You'd have to setup some javascript that fires off a message to your server every x seconds and acts like a pulse. If you "loose the pulse" then you'd write their session to the database.


On Sun, Apr 18, 2010 at 8:22 PM, Tuna Toksoz <teh...@gmail.com> wrote:
>

> May not work.  What if ...

Reply all
Reply to author
Forward
0 new messages