Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Listbox item added with client scripts not submitting with ASP:Listbox

Reply
Thread Tools

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

 
 
Simon Prince
Guest
Posts: n/a
 
      10-18-2004
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]


 
Reply With Quote
 
 
 
 
jjardine
Guest
Posts: n/a
 
      10-19-2004

"Simon Prince" <(E-Mail Removed)> wrote in message
news:cl0ohg$qh7$1$(E-Mail Removed)...
> 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?


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
Guest
Posts: n/a
 
      10-19-2004
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]
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Solution for posterity: GridView, Datakeys, and "Item has already been added. Key in dictionary: 'CategoryID' Key being added: 'CategoryID'" ASP .Net 2 11-02-2006 04:48 AM
WebControl - CollectionEditor Problem. Changing id property of new added collection item causes not adding item to collection - Sergio ASP .Net Web Controls 0 05-29-2006 06:20 AM
Copying data from one server control ListBox to another using client-side scripts Shary ASP .Net Web Controls 2 12-07-2004 05:54 PM
Listbox not submitting correctly? Damien Foggon ASP .Net Web Controls 1 10-23-2003 01:51 PM
Listbox not submitting correctly? Damien Foggon ASP .Net 1 10-23-2003 01:51 PM



Advertisments