473,387 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

adding items to <asp:ListBox> via javascript

Hello.

I have an application where I need the user to be able to add items to a
listbox. I've implemented this via javascript. The listbox is an
<asp:ListBox>. However, when the user submits the form those items do not
get posted. My listbox.Items.Count always returns 0.

I want the user to be able to add items without having to resort to a
postback, hence the javascript. But I need to be able to access those items
in the code behind page as well. Any thoughts on how this is best achieved?

Thanks in advance.
Ryan Taylor
Nov 19 '05 #1
3 2695
I don't think that can happen. When you populate a listbox on the server,
all that stuff is stored via viewstate (which is how the listbox stays
populated after a postback). Since you can't hack the viewstate, I don't see
how you could keep the listbox populated, other then passing the items that
should go in it as a list in a hidden input or something, and manually
populating on the server.
"Ryan Taylor" <rt*****@stgeorgeconsulting.com> wrote in message
news:uO**************@TK2MSFTNGP14.phx.gbl...
Hello.

I have an application where I need the user to be able to add items to a
listbox. I've implemented this via javascript. The listbox is an
<asp:ListBox>. However, when the user submits the form those items do not
get posted. My listbox.Items.Count always returns 0.

I want the user to be able to add items without having to resort to a
postback, hence the javascript. But I need to be able to access those
items
in the code behind page as well. Any thoughts on how this is best
achieved?

Thanks in advance.
Ryan Taylor

Nov 19 '05 #2
That is really unfortunate. To put the application into context, the
application is allowing a logged in user to add new employees. The listbox
is a list of degrees that the employee may have. You can create new
employees, edit employees and delete employees. As such, the degrees listbox
needs to be able to insert/remove degrees. I really wanted to avoid using a
postback because it looks unprofessional, it should appear that the form is
only posted once. Also, and this is the worst part, when the page does a
postback after adding an item to the listbox, the page resets so we are now
at the top of the page. Since this is a very long form, the user is forced
to scroll back down to the bottom of the page.

If there was at least a solution to resume in the same location as before
the postback, then that might be acceptable.
Thanks for replying so quickly.

Ryan Taylor
Nov 19 '05 #3
Yes, this is possible...not using standard techniques though.

See
http://www.dart.com/livetutorial/dis...ist%20Controls

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
4
by: Sally | last post by:
Any ideas on how you handle this in the control? I am using C# if that matters. Want to pass an array or even do id.AnArray=myarry; -Sal
10
by: Adam Clauss | last post by:
I have a page containing a list box. This list may contain duplicate items - in which the ORDER is important. ex: a b b a is significant as compared to: b
1
by: bill | last post by:
I need to be able to dynamically add items to a <asp:listbox> (or HTML <select runat=server>) using clientside javascript, and retrieve the items when the page is posted back. I use this code to...
4
by: Kevin Blount | last post by:
As mentioned before, I'm creating a multi-lingual page where the text of the page comes from a database. This page includes a registration form which asks for address information, including the...
2
by: Mark Rae | last post by:
Hi, Looking for some advice again... Imagine two ListBox controls denoting something like students and team membership e.g. many students can be members of many teams (e.g. the hockey team,...
0
by: sasankasekhar2003 | last post by:
i have a textbox txtName (web form element) 2 listboxes lstAll (web form element) (autopostback=false, select=multiple) lstSel (web form element)(autopostback=false,...
7
by: mikeh3275 | last post by:
I'm creating a .net program that uploads images to the FTP server. A blank listbox is populated dynamically on the client side from the value of the html input file widget. There is also a...
1
by: Jeff | last post by:
hi asp.net 3.5 (project upgraded from asp.net 2.0). are using vwd2008 express now This is my first ajax attempt. The code below shows a TextBox and a ListBox. The idea I was trying to...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.