Thursday, March 29, 2012

List Box Populated Client Side

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
KMOn Mon, 26 Dec 2005 09:55:56 -0800, math.kiran wrote:

> 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.
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
On Mon, 26 Dec 2005 11:22:53 -0800, JaduBlue wrote:

> 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.
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.

0 comments:

Post a Comment