views:

443

answers:

2

I have a shopping cart based application in asp.net 2.0 which uses the concept of group buying.My requirement is that when user checks out a particular product,he should do it with the latest price of that item at that time.

Now there is a scenario.

I have a product with price 50.I did a checkout.50 is displayed in my cart.At the same time some other user is accessing the product and now based on some business logic,we calculate the price.the second user did some activity which reduced the price to 45. I have a trigger which updates all shopping cart items with this new price.

I want to show this updated price on the frontend of the first user without a postback. or i want to give him a message that this price has changed so do a page refresh.

I have the following options.

1) The repeater control which shows the cart should be put under an update panel and that update panel should be refreshed after some interval using a timer.

2) use SQL Server notification services and invalidate the cache as soon as the data changes in database.

I do not want to use notification services as I am not caching the data.Secondly problem with update panel and timer control in that it will be a overhead to refresh it and refresh time is hard to find.

Please tell me a way to accomplish this scenario.

A: 

This is usually done via ajax from the client (browser) side of things. Perhaps this approach will work for your requirements as well?

Using ExtJs core, you can make an ajax call as follows:

Ext.Ajax.request({
   url: 'ajax_demo/sample.aspx',
   params : {'requestType':'check-sql-prices'}
   success: function(response, opts) {
      var obj = Ext.decode(response.responseText);
      // process the response JSON object.
   },
   failure: function(response, opts) {
      // this writes the the firebug console.
      console.log('server-side failure with status code ' + response.status);
   }
});

Ext Core also handles "Timed Code Execution", so you could run the check, say, every 30 seconds. Round trip timing is usually less than 100 milliseconds, but that would definitely depend on your "SQL price checking" logic.

Joshua
u mean to use page methods,In that case also i have to find a time interval to call that page method again.
Rohit
A: 

I would generate JavaScript that updates all Repeater items (html fields with prices), and has setTimeout() for periodical checking to web service (wcf, asmx or ashx) if price has changed. If it has, then i would retrieve all prices and update HTML fields! User don't need to prees anything, you can show him some notice that price has changed.
With jQuery and JSON for object serialisation this could be easily accomplished.

Hrvoje