472,981 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,981 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 2673
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...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.