473,407 Members | 2,359 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,407 software developers and data experts.

Listbox item added with client scripts not submitting with ASP:Listbox

Help

I have a ASP:Listbox on a form. My page Adds items to this this via
Client-Side Script only.
Such as...

var vObj_TargetElement =
document.getElementById("_PageTemplate_innerHolder _oASP_Lbx_Invoice");
var vObj_SourceElement = document.getElementById("oHTML_Tbx_Invoice");
var vInt_OptionTotal = vObj_TargetElement.length++;
vObj_TargetElement.options[vInt_OptionTotal].value =
Trim(vObj_SourceElement.value);
vObj_TargetElement.options[vInt_OptionTotal].text =
Trim(vObj_SourceElement.value);
When the form is submitted, these new items are not submitted within the
LISTBOX.

Server-Side code such as ...
Response.Write(oASP_Lbx_Invoice.Items.Count.ToStri ng)

Returns 0 (zero)

Any ideas how to solve this ??

Thanks.

Simon

[Remove the NOSPAM if replying by email]
Nov 18 '05 #1
2 1433

"Simon Prince" <si**********@joseph.NOSPAM.co.uk> wrote in message
news:cl*******************@news.demon.co.uk...
Help

I have a ASP:Listbox on a form. My page Adds items to this this via
Client-Side Script only.
Such as...

var vObj_TargetElement =
document.getElementById("_PageTemplate_innerHolder _oASP_Lbx_Invoice");
var vObj_SourceElement = document.getElementById("oHTML_Tbx_Invoice");
var vInt_OptionTotal = vObj_TargetElement.length++;
vObj_TargetElement.options[vInt_OptionTotal].value =
Trim(vObj_SourceElement.value);
vObj_TargetElement.options[vInt_OptionTotal].text =
Trim(vObj_SourceElement.value);
When the form is submitted, these new items are not submitted within the
LISTBOX.

Server-Side code such as ...
Response.Write(oASP_Lbx_Invoice.Items.Count.ToStri ng)

Returns 0 (zero)

Any ideas how to solve this ??

Thanks.

Simon

[Remove the NOSPAM if replying by email]


It looks as though a listbox is read only as far as once it goes down to the
client as html. The server control does not look at what happens to the
list box once it leaves the server. When you go back to the server it uses
the server version to reload the box. I messed around with the code you
posted and that seems to be what is happening. It seems to be a one way
street. Is there any way to have the listbox do a postback to update it?
Nov 18 '05 #2
The way it is normally done is through a hidden field. Whenever your
client-side script runs to add the value to the list, add it to the hidden
field as well. On postback repopulate the listbox with the values from the
hidden field. You need to be careful because, if I remember correctly, the
listbox will retain whatever values were in it when it was originally sent to
the client. So either handle this case or always have the hidden field
represent values that were added during the current client session (prior to
postback).

I have seen a custom control somewhere that did just what you wanted but I
can't remember where. You could try Code Project or Code Guru.

Michael Taylor, MCP - 10/19/04

"Simon Prince" wrote:
Help

I have a ASP:Listbox on a form. My page Adds items to this this via
Client-Side Script only.
Such as...

var vObj_TargetElement =
document.getElementById("_PageTemplate_innerHolder _oASP_Lbx_Invoice");
var vObj_SourceElement = document.getElementById("oHTML_Tbx_Invoice");
var vInt_OptionTotal = vObj_TargetElement.length++;
vObj_TargetElement.options[vInt_OptionTotal].value =
Trim(vObj_SourceElement.value);
vObj_TargetElement.options[vInt_OptionTotal].text =
Trim(vObj_SourceElement.value);
When the form is submitted, these new items are not submitted within the
LISTBOX.

Server-Side code such as ...
Response.Write(oASP_Lbx_Invoice.Items.Count.ToStri ng)

Returns 0 (zero)

Any ideas how to solve this ??

Thanks.

Simon

[Remove the NOSPAM if replying by email]

Nov 18 '05 #3

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

Similar topics

10
by: yop | last post by:
All When I try to get the text from my listbox I am get an error which is listed below. Any ideas? Thanks Object reference not set to an instance of an object.
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...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
6
by: Steve | last post by:
Hi, I open up a webform (vb.net) and populate a listbox control on the Page load event. If I click on (select) and item from the listbox I want to write the value of the selected item to a...
4
by: Bob P. | last post by:
Hello, I have a page with: * two side-by-side asp:listboxes and two arrow asp:buttons allowing users to add/remove email addresses between them -- very much like Outlook, where you have the...
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
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,...
2
by: teo | last post by:
I have a Listbox, if I set EnableViewStarte = False the AutopostaBack fired by SelectedIndexChanged doesn't work. The 'SelectedIndexChanged' event should call
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
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,...
0
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...

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.