ListBox items changed client-side are not available server-side

Discussion in 'ASP .Net' started by Valerian John, May 15, 2004.

  1. I have a ListBox webcontrol on an aspx page. Items are added to the
    ListBox using client-side code. However, when the page is posted back the
    items are missing/not available. (It is like the page does not know the
    items were added client-side.)

    TIA,
    Val
    Valerian John, May 15, 2004
    #1
    1. Advertising

  2. Hi Valerian John,

    Returning values from a client side encoded page is
    entirely dependent on your client side code. I assume when
    you say "client side", you are talking about JavaScript?
    Is your listbox view state enabled? Does it carry out auto
    postback? There are various strategies available to post
    back client side added data. I use a very basic method,
    which involves naming my control (in your case a list
    box), and setting it's values equal to your client added
    values. On the server side, you will simply have to pull
    the values out of the request string and do with them
    whatever you want to do.

    Regards
    Ashish M Bhonkiya

    "Valerian John" <> wrote in message
    news:%23kOcm$...
    > I have a ListBox webcontrol on an aspx page. Items are added to the
    > ListBox using client-side code. However, when the page is posted back the
    > items are missing/not available. (It is like the page does not know the
    > items were added client-side.)
    >
    > TIA,
    > Val
    >
    >
    Ashish M Bhonkiya, May 16, 2004
    #2
    1. Advertising

  3. The ViewState of a webcontrol is a collection of the control's properties.
    When you add items on client-side, you are using options collection of a
    select object, aren't you? Probably it doesn't translate to ListBox Items
    property and therefore doesn't get posted back.

    Eliyahu

    "Valerian John" <> wrote in message
    news:%23kOcm$...
    > I have a ListBox webcontrol on an aspx page. Items are added to the
    > ListBox using client-side code. However, when the page is posted back the
    > items are missing/not available. (It is like the page does not know the
    > items were added client-side.)
    >
    > TIA,
    > Val
    >
    >
    Eliyahu Goldin, May 16, 2004
    #3
  4. Ashish:

    Thanks for your response.
    Here is the basic JavaScript function I am using for adding an OPTION
    element to the SELECT created by the ListBox webcontrol. The item/option is
    added to the ListBox but after postback when I list the items in the ListBox
    this newly added item is missing.

    Button1 is a HTML button & Button2 is Button webcontrol. Button1's onclick
    attribute is set to the client-side addOption() function. Button2 does the
    postback and calls the server-side GetItems() proc. TextBox1 is a
    multi-line Textbox webcontrol used to display all the ListBox items. The
    ListBox's AutoPostBack property is set to false & its EnableViewState is
    true.

    function addOption() {
    var oListBox=document.getElementById('ListBox1');
    var oOption = document.createElement("OPTION");
    oOption.text="Test";
    oOption.value="Test";
    oListBox.add(oOption);
    return true;
    }

    Private Sub GetItems()
    Dim i As Integer=0
    While (i < ListBox1.Items.Count)
    TextBox1 .Text += ListBox1.Items(i).Text + vbNewLine
    i += 1
    End While
    TextBox1 .Text += ListBox1.Items.Count.ToString + vbNewLine
    End Sub

    Appreciate your input/help,
    Val



    "Ashish M Bhonkiya" <> wrote in message
    news:...
    > Hi Valerian John,
    >
    > Returning values from a client side encoded page is
    > entirely dependent on your client side code. I assume when
    > you say "client side", you are talking about JavaScript?
    > Is your listbox view state enabled? Does it carry out auto
    > postback? There are various strategies available to post
    > back client side added data. I use a very basic method,
    > which involves naming my control (in your case a list
    > box), and setting it's values equal to your client added
    > values. On the server side, you will simply have to pull
    > the values out of the request string and do with them
    > whatever you want to do.
    >
    > Regards
    > Ashish M Bhonkiya
    >
    > "Valerian John" <> wrote in message
    > news:%23kOcm$...
    > > I have a ListBox webcontrol on an aspx page. Items are added to the
    > > ListBox using client-side code. However, when the page is posted back

    the
    > > items are missing/not available. (It is like the page does not know the
    > > items were added client-side.)
    > >
    > > TIA,
    > > Val
    > >
    > >

    >
    >
    Valerian John, May 16, 2004
    #4
  5. Eliyahu:

    Thanks for your response.
    Yes, I am using the Options collection of the Select element.
    The ListBox webcontrol is rendered as an HTML Select so I figured I should
    be able to manipulate it client-side.
    I am wondering if one must call a built-in client-side function (similar to
    __doPostBack) that registers that the ListBox's items were altered and that
    changes must be passed via ViewState on postback.

    TIA,
    Val

    "Eliyahu Goldin" <> wrote in message
    news:...
    > The ViewState of a webcontrol is a collection of the control's properties.
    > When you add items on client-side, you are using options collection of a
    > select object, aren't you? Probably it doesn't translate to ListBox Items
    > property and therefore doesn't get posted back.
    >
    > Eliyahu
    >
    > "Valerian John" <> wrote in message
    > news:%23kOcm$...
    > > I have a ListBox webcontrol on an aspx page. Items are added to the
    > > ListBox using client-side code. However, when the page is posted back

    the
    > > items are missing/not available. (It is like the page does not know the
    > > items were added client-side.)
    > >
    > > TIA,
    > > Val
    > >
    > >

    >
    >
    Valerian John, May 16, 2004
    #5
  6. Valerian,

    Have a look at
    http://www.metabuilders.com/Tools/DynamicListBox.aspx

    Eliyahu

    "Valerian John" <> wrote in message
    news:%...
    > Eliyahu:
    >
    > Thanks for your response.
    > Yes, I am using the Options collection of the Select element.
    > The ListBox webcontrol is rendered as an HTML Select so I figured I should
    > be able to manipulate it client-side.
    > I am wondering if one must call a built-in client-side function (similar

    to
    > __doPostBack) that registers that the ListBox's items were altered and

    that
    > changes must be passed via ViewState on postback.
    >
    > TIA,
    > Val
    >
    > "Eliyahu Goldin" <> wrote in message
    > news:...
    > > The ViewState of a webcontrol is a collection of the control's

    properties.
    > > When you add items on client-side, you are using options collection of a
    > > select object, aren't you? Probably it doesn't translate to ListBox

    Items
    > > property and therefore doesn't get posted back.
    > >
    > > Eliyahu
    > >
    > > "Valerian John" <> wrote in message
    > > news:%23kOcm$...
    > > > I have a ListBox webcontrol on an aspx page. Items are added to the
    > > > ListBox using client-side code. However, when the page is posted back

    > the
    > > > items are missing/not available. (It is like the page does not know

    the
    > > > items were added client-side.)
    > > >
    > > > TIA,
    > > > Val
    > > >
    > > >

    > >
    > >

    >
    >
    Eliyahu Goldin, May 17, 2004
    #6
  7. Eliyahu:

    Thanks for that url. I am testing out his DynamicListBox for this problem.
    Found some other useful controls there.

    Val


    "Eliyahu Goldin" <> wrote in message
    news:...
    > Valerian,
    >
    > Have a look at
    > http://www.metabuilders.com/Tools/DynamicListBox.aspx
    >
    > Eliyahu
    >
    > "Valerian John" <> wrote in message
    > news:%...
    > > Eliyahu:
    > >
    > > Thanks for your response.
    > > Yes, I am using the Options collection of the Select element.
    > > The ListBox webcontrol is rendered as an HTML Select so I figured I

    should
    > > be able to manipulate it client-side.
    > > I am wondering if one must call a built-in client-side function (similar

    > to
    > > __doPostBack) that registers that the ListBox's items were altered and

    > that
    > > changes must be passed via ViewState on postback.
    > >
    > > TIA,
    > > Val
    > >
    > > "Eliyahu Goldin" <> wrote in message
    > > news:...
    > > > The ViewState of a webcontrol is a collection of the control's

    > properties.
    > > > When you add items on client-side, you are using options collection of

    a
    > > > select object, aren't you? Probably it doesn't translate to ListBox

    > Items
    > > > property and therefore doesn't get posted back.
    > > >
    > > > Eliyahu
    > > >
    > > > "Valerian John" <> wrote in message
    > > > news:%23kOcm$...
    > > > > I have a ListBox webcontrol on an aspx page. Items are added to

    the
    > > > > ListBox using client-side code. However, when the page is posted

    back
    > > the
    > > > > items are missing/not available. (It is like the page does not know

    > the
    > > > > items were added client-side.)
    > > > >
    > > > > TIA,
    > > > > Val
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Valerian John, May 17, 2004
    #7
    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. Stuart Dickerson
    Replies:
    0
    Views:
    2,990
    Stuart Dickerson
    Aug 29, 2003
  2. nick
    Replies:
    3
    Views:
    3,166
    Eliyahu Goldin
    Dec 15, 2004
  3. bogdan
    Replies:
    2
    Views:
    882
    bogdan
    Apr 28, 2008
  4. Joe Abou Jaoude
    Replies:
    2
    Views:
    158
    Joe Abou Jaoude
    Nov 18, 2004
  5. nick
    Replies:
    1
    Views:
    204
    Victor Garcia Aprea [MVP]
    Dec 23, 2004
Loading...

Share This Page