473,810 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.C ount 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 2730
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*****@stgeor geconsulting.co m> wrote in message
news:uO******** ******@TK2MSFTN GP14.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.C ount 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
8426
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 I want to do is to allow the user to click on the row that corresponds to the correct address, and have the code behind populate the form's Address1, Address2 etc. controls with the relevant data items. I put the code for this into the...
4
1563
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
3308
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
12796
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 add the option to the listbox. It works for <select> or <asp:listbox> controls. var opt = document.CreateElement("OPTION"); opt.text = "test"; opt.value="test";
4
4701
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 Country. I have 6 .txt files that contain a complete list of countries that we sell to (65 in total), each written in the appropriate way for the language of the site, e.g. Mexico for English US and UK sites and México for the Spanish language...
2
3620
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, the football team, the athletics team etc). Team membership is managed on a standard web page with two ListBox controls - the one on the left shows which team(s) the student is not a
0
996
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, select=multiple) in my ASPX page form. Listbox lstAll is populated on load from the database.
7
3238
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 requiredfieldvalidator on the listbox to make sure there is an item in the listbox. When I click the button to submit, however, the listbox clears itself and a validation error shows. Below is the relevant code in C# plus the Javascript code. Thanks in...
1
5351
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 accomplish was that the items in the ListBox was automatically filtered as the user type text into the textbox... But nothing happens. The OnTextChanged event isn't even fired when I type in the textbox.
0
9722
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.