Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox Count Problem

Status
Not open for further replies.

JabbaTheNut

Programmer
Jul 29, 2002
176
US
I have a list box that is editable on the client side (i.e., adding items and deleting items). These edits are done in javascript. The problem I am having is that the count property of the list box is not providing a correct count. For example...

If the list box was initially empty when it went to the client and the client added 5 items through javascript, the following code evaluates to 0 instead of 5:

<code>
myList.Items.Count
</code>

In javascript, items are added to the list box as follows:

<code>
var newopt = new Option();
newopt.value = someValue;
newopt.text = someText;
myList.add(newopt, myList.options.length);
</code>

This javascript works great for adding items to the end of the list. Why does the code-behind not recognize the number of items?

Game Over, Man!
 
It would seem (as indicated from posts to other forums) that client-side javascript changes to the list cannot be seen on the server side. The only workaround I have seen so far is to loop through the list with javascript and concatenate a string of the value and text pairs in the list, separating the value and text items with a comma and then separating the pairs with a semi-colon. The string is then input into a hidden html text box. Then, when the form is posted to the server, the server-side code can split the string from the hidden html text box into a multi-dimensional array that can be saved to the database.

This seems to be a bit short-sighted on the list control designers part. I thought it was fairly common to move items from one list to another using javascript. Why was this not taken into account in the design of the list box control?

Game Over, Man!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top