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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

lsit boxes

Status
Not open for further replies.

Stunner01225

Technical User
Mar 13, 2002
150
GB
Just a quick and simple question, but I cannot find the answer.
I have an empty list box web control on an aspx page. I use javascript on the client side to add items to it but when I post back to the server I cannot see them and items .count is returning 0 .
What am I doing wrong?

Cheers for any help.
 
i've seen this as well...the listbox has a datasource property that is server side...so as far as your listbox knows, there is nothing in it...

is there a reason to populate it client side? I'm not sure if there is a way to post it to the datasource of the listbox.

"...we both know I'm training to become a cagefighter...see what happens if you try 'n hit me..."
 
What javascript code are you using to add the items?

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
a custom function
function addItem(varNo , varText)
{
var myBox = document.getElementById("lbCom");
var newOp = new Option(varText,varNo);
myBox.add(newOp, myBox.length);
}

The javascript adds them to the box , or at least it shows them.

The reason im working like this is because im using a tree check list web control, and I thought this would be a quicker way to find the checked nodes.
 
OK - I've done something similar n the past but it's not elegant!

From what I remember I:

1) Created a hidden textbox that is populated with a comma seperated string of the items in the listbox. This is populated from a javascript function when the user clicks the submit button.

2) Got the contents of that hidden textbox from the Request.Form object and repopulated it server side

As I said it's not very elegant but as those items are added client side, they don't actually exist as far as the server control is concerned.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Thanks ca8msm , I was coming to the same conclusion my self.
I thought when I started this code that it was too easy.

Thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top