Calling response.IsClientConnected from Javascript

Hey people.. hope you are all well

I have a shopping cart that uses ASP session arrays to store the cart data....
My problem is:
    - A customer adds products to the cart, and the stock levels are adjusted accordingly (but does NOT buy them).. GREAT

    - BUT then the customer gets disconnected from the web site for one reason or another (line dropped or simply went to    
      another site).. . NOT GREAT as those products that were in the shopping cart have not been put back into stock and have  

I looked on the net and found response.IsClientConnected, which returns true/false   COOL  so my plan was to use a function with these basic parts, which would be on every customers browser.

Every n seconds
  If our customer is NOT conencted
        Put their cart qtys back into stock
        do nothing
  end if

i was also going to put this into the onLoad part in the BODY tag...  but i could not get it to run a ASP function.

Hense, is there a way to run the ASP function from Javascript function, as this onLoad thing seems to like Javascript functions.


Does anyone have any other ideas that would help me out :)

Thanks in advance people

And have a great and groovy day.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems architectCommented:
From my point of view does browser side script not help you.

You have to rethink your complete concept.
The problem starts here:
   - A customer adds products to the cart, and the stock levels are adjusted accordingly (but does NOT buy them).. Not GREAT

Better would be to substract the stock amount first on the counter.
That implies more handling and scripting, but that is the only correct way because the items are not sold as long they do not get payd.

refresh the page every adjusted seconds


10 is in seconds

in your asp page you can check it

but the better solution is
using Session On End in global.asa

Sub Session_OnEnd
write the code here that
Puts their cart qtys back into stock

End Sub


CybordaxAuthor Commented:
Tried the above for the Session_OnEnd  and it did not work...

basically this is my coding

      ARYShoppingCart = session("ShoppingCart")
      icount = session("ItemCount")
      ARYSOCart = session("SOCart")
      SOiCount = session("SOCount")
      for a = 1 to 100
            ARYShoppingCart(1,a) = ""
            ARYShoppingCart(2,a) = ""
            ARYShoppingCart(3,a) = ""
            ARYShoppingCart(4,a) = ""
            ARYShoppingCart(5,a) = ""
            ARYShoppingCart(6,a) = ""
            ARYShoppingCart(7,a) = ""
            ARYShoppingCart(8,a) = ""
            ARYShoppingCart(9,a) = ""
      for a = 1 to SOiCount
            for b = 1 to 20
                  ARYSOCart(a,b) = ""
      SOiCount = 0
      iCount = 0
      session("ShoppingCart") = ARYShoppingCart
      session("ItemCount") = icount
      session("SOCart") = ARYSOCart
      session("SOCount") = SOiCount
      application("active")=application("active") - 1

i have put the "application" lock unlock etc before, after and in between my coding... but still no joy...

Any other ideas...

Thanks in advance
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

when you close the broser it doesnt the fire Session_OnEnd directly
check the session time out and  visit the page after a long time > Session.Timeout

in your code
you used Sessions
Sessions also be lost when the session ends

you have to try to use temp table to keep the shopping cart
(do not increase the stcok)
when the user closes the browser delete inside of the table

when the shopping card is completed and submitted (purchased)
then icrease the stock
delete inside of the table

maybe this gives an idea :)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CybordaxAuthor Commented:
hmmm...  temp table possibly...

i need to increase the stock (well the stock allocated)

say i have 50 items in stock and 3 people or more go on line...

one adds 10 to the cart, then the other person goes to add the same item, then should see a real time allocation i.e.   50 original stock items minus what is allocated to the web shopper...
so they should see 40, then when the second user adds 5, any other users will see 35 etc...

its pretty much real time stock figures...

a temp table could be good though, cos i could make a prog that sits on the server and polls the database for inactive rows... for say 20 mins, then puts them back into stock upon inactivity...

but i still need to trap when the user quits, or goes to another web site, because they could close the window, down and come back in 5 minutes later, the old cart data would still be in the temp table.....


you can only trace the online user
if logged
on logout (do logout jobs)

if the user closes the browser
then the only way you can do is use session_onend

 session on end doesnt the fire the code immediately
but it fires the code :) myabe a bit later

keep the session.timeout less

CybordaxAuthor Commented:
now THAT sounds like a plan...

i will do that and keep session timeouts to.........  5 mins  for example.....

or for testing purposes....   1 min...

I will get back to you...

Cheers, my friend
CybordaxAuthor Commented:
Still does not work...

on session OnStart i set the timeout to 1 min
i add something to the cart... and then wait for a min or so....

on the session onEnd thing..
i make it go through the cart array and add various partcodes and qtys to a txt string
then i write to a file....

and look for that file manually....

But... still does not kick in.....

i may just do the thing where i make a program that checks the database every min or so, and checks the last modified time of the rows and if greater than recorded time + 5 mins, then put stock back and delete the row.....
and i will set session timeout to.... 10 mins or something....  then delete regardless of user...

i will try that.....

that should work......

I will accept the answer you gave about "temp table"
I am also using session on end

when the user logged

i got the user_id from database and Session.SessionID
write it to users lo database

on the session on one event

i call the function that  deletes user log from database

DeleteUserLog(ByVal UserID, Byval SessionID)

I also immediately didnt see result (didnt delete the users log)

next time i enter the site, i saw that the user log was deleted


It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.