1

I have a ASP web application that uses listboxes. My dilemma is that changes in items selection on the listboxes will happen fast and frequently, so doing a postback to get the information that I need would end up being very slow on the client side.

My question is: What is the best way to store data on the client side? or should I just use something like Postback, or ajax?

The information that needs to be stored could be in a single string for each item that I can split, but there will need to be the information for all of the items in the Listbox and the number of items in the Listbox is unknown.

Please let me know what you think would be the best place to have the information.

Seige
  • 304
  • 5
  • 27
  • I have been thinking about using "hiddenfields" and create them onload of the page in ASP. I can use the Values of these to put in a information string that i can split and use in the javascript. Do you think this could be a good idea? – Seige Mar 15 '12 at 20:40

3 Answers3

2

It really depends on how far you want to take things. Postback will be quick to implement but may prove to be awkward and slow. Using ajax in one way or another will speed things up considerably and there are many ways this can be used. The extent of which will be determined by how much time you want to spend developing it vs the benefit to the user / frequency of use.

As a specific answer I would suggest AJAXing the data in, but whether you do this every time you need it or once on load, would depend on application/context.

g.foley
  • 2,152
  • 3
  • 19
  • 27
1

As g.foley wrote it is context specific and can't be answered without getting more details.
I can say I used to hold a JavaScript object that I sent only on submit of a form, maybe this approach will suite you.

Dror
  • 7,255
  • 3
  • 38
  • 44
  • So you are using a Javascript object to hold all the information? Is there a way to store a "global" object, that wont clear when a function is finished? – Seige Mar 15 '12 at 20:38
  • You could use HTML5 localStorage - see some discussion in http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage – Dror Mar 16 '12 at 04:00
0

From the sub-context of the question, I'm going to make a guess that you don't really need information from the server when selection on listboxes changes? If I'm right, then you can store the information in the javascript variables and then right before the browser navigates to another page/closes (onBeforeUnload) post the data back to the server through AJAX. This way you will cut back on the constant communication with the server. If you do end using this method, be aware that Chrome really doesn't like Async AJAX calls on unload or beforeUnload. You will need to make your call synchronous. IE also doesn't like it, but with a different result. You might actually lose a connection to the server, so when the next page loads from your website instead of using 4/6 connections simultaneously, you will only have 3/5 available.

If I guessed wrong, then your best bet is AJAX call to the server when selection changes. That would be the fastest way to get information (other than WebSockets).

Ilya Volodin
  • 10,929
  • 2
  • 45
  • 48
  • Unfortunatly, I am needing to get the information for each item selection in the listbox. Otherwise i would be able to get away with just using ASP between pages. AJAX seems to be the way the answers are going. So probably see how that goes. – Seige Mar 15 '12 at 20:33