List Box Populated Client Side

M

math.kiran

I have a list box which gets populated client side (Javascript).

Now when I submit the page - I need to capture all the list item and
store it in database.

What is the elegant way to do it in asp.net?

Thanks
KM
 
I

intrader

I have a list box which gets populated client side (Javascript).

Now when I submit the page - I need to capture all the list item and
store it in database.

What is the elegant way to do it in asp.net?

Thanks
KM
Use XML to encode the option array
corresponding to the select in a hidden type field. To this effect
you either enumerate the option array, or give all the options the same id
(as in <option id=myoption value=1>one</option>) and enumerate
document.all.myoption.
You should build xml like:
<myoption value=1>
<myoption value=2>
....

Once you receive the object representing the options you can store this in
the database via a stored procedure that accepts the XML as a parameter,
loads the XML into a temporary dom and processes this dom via a select.
 
J

JaduBlue

Are you saying to create a client side XML data island.

Yes that is a way to go -- but don't you think it might be a problem
with browsers like firefox etc.

Thanks
 
I

intrader

Are you saying to create a client side XML data island.

Yes that is a way to go -- but don't you think it might be a problem
with browsers like firefox etc.

Thanks
A data island is one possibility. However, what I suggest is just a hidden
variable that contains the XML for a collection of <option>s
I hope this is clear.
 
P

Praveen

Hi,
There is an indirect way to get all the list items at the server side
which are added from the client side javascript.
We can retrieve all the list items(only the selected list item values)
using
Request.Form("lstCountries")

So before posting back to the server, make all the list items selected
= true.
using the script code function call
like

function selAll(){
var lst = document.getElementById("lst1");
var j=0;
for(j=lst.length-1;j>=0;j--){
lst.options[j].selected=true;
}
}

THen at the server side, just retrieve using Request.Form("lst1");

Bye,
Praveen P.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,160
Latest member
CollinStri
Top