473,698 Members | 2,554 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_TargetElem ent =
document.getEle mentById("_Page Template_innerH older_oASP_Lbx_ Invoice");
var vObj_SourceElem ent = document.getEle mentById("oHTML _Tbx_Invoice");
var vInt_OptionTota l = vObj_TargetElem ent.length++;
vObj_TargetElem ent.options[vInt_OptionTota l].value =
Trim(vObj_Sourc eElement.value) ;
vObj_TargetElem ent.options[vInt_OptionTota l].text =
Trim(vObj_Sourc eElement.value) ;
When the form is submitted, these new items are not submitted within the
LISTBOX.

Server-Side code such as ...
Response.Write( oASP_Lbx_Invoic e.Items.Count.T oString)

Returns 0 (zero)

Any ideas how to solve this ??

Thanks.

Simon

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

"Simon Prince" <si**********@j oseph.NOSPAM.co .uk> wrote in message
news:cl******** ***********@new s.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_TargetElem ent =
document.getEle mentById("_Page Template_innerH older_oASP_Lbx_ Invoice");
var vObj_SourceElem ent = document.getEle mentById("oHTML _Tbx_Invoice");
var vInt_OptionTota l = vObj_TargetElem ent.length++;
vObj_TargetElem ent.options[vInt_OptionTota l].value =
Trim(vObj_Sourc eElement.value) ;
vObj_TargetElem ent.options[vInt_OptionTota l].text =
Trim(vObj_Sourc eElement.value) ;
When the form is submitted, these new items are not submitted within the
LISTBOX.

Server-Side code such as ...
Response.Write( oASP_Lbx_Invoic e.Items.Count.T oString)

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_TargetElem ent =
document.getEle mentById("_Page Template_innerH older_oASP_Lbx_ Invoice");
var vObj_SourceElem ent = document.getEle mentById("oHTML _Tbx_Invoice");
var vInt_OptionTota l = vObj_TargetElem ent.length++;
vObj_TargetElem ent.options[vInt_OptionTota l].value =
Trim(vObj_Sourc eElement.value) ;
vObj_TargetElem ent.options[vInt_OptionTota l].text =
Trim(vObj_Sourc eElement.value) ;
When the form is submitted, these new items are not submitted within the
LISTBOX.

Server-Side code such as ...
Response.Write( oASP_Lbx_Invoic e.Items.Count.T oString)

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
2247
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
8394
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...
6
2874
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 a denormalized mirror of the database, but I'm not having much luck getting the selection logic down (I haven't found a 'hook' where I can access the listbox object as an object to set the listitem's selected property before it gets rendered).. ...
1
2262
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 button_click function because the only way to find the listbox is: (listbox)e.item.findcontrol What s the solution to this problem?
6
6179
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 label control. Nothing happens. But when I click a button (which contains same code to write to label) I get the value of the selected item in the Label.
4
5098
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 address book on the left, and you build the message recipients on the right. * an asp:button that, when clicked, fires off some code to create and send the mail message
10
3290
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
3614
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
2
2913
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
8612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9032
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
8905
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
8880
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
4373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2342
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.