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

Discussion in 'ASP .Net' started by Simon Prince, Oct 18, 2004.

  1. Simon Prince

    Simon Prince Guest

    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.ToString)

    Returns 0 (zero)

    Any ideas how to solve this ??

    Thanks.

    Simon

    [Remove the NOSPAM if replying by email]
    Simon Prince, Oct 18, 2004
    #1
    1. Advertising

  2. Simon Prince

    jjardine Guest

    "Simon Prince" <> wrote in message
    news:cl0ohg$qh7$1$...
    > 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.ToString)
    >
    > 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?
    jjardine, Oct 19, 2004
    #2
    1. Advertising

  3. RE: Listbox item added with client scripts not submitting with ASP:Lis

    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.ToString)
    >
    > Returns 0 (zero)
    >
    > Any ideas how to solve this ??
    >
    > Thanks.
    >
    > Simon
    >
    > [Remove the NOSPAM if replying by email]
    >
    >
    >
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=, Oct 19, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Damien Foggon

    Listbox not submitting correctly?

    Damien Foggon, Oct 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    339
    Nicole Calinoiu
    Oct 23, 2003
  2. Bennett Haselton
    Replies:
    1
    Views:
    504
    John M Deal
    Nov 8, 2004
  3. davidj411
    Replies:
    0
    Views:
    481
    davidj411
    Jun 27, 2008
  4. Damien Foggon

    Listbox not submitting correctly?

    Damien Foggon, Oct 23, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    105
    Nicole Calinoiu
    Oct 23, 2003
  5. Sergio
    Replies:
    0
    Views:
    261
    Sergio
    May 29, 2006
Loading...

Share This Page