By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,905 Members | 894 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,905 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2

P: n/a
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" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #3

P: n/a
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" <bh******@hotmail.com.nospam> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
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" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #4

P: n/a
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" <re*************@monarchmed.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
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" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #5

P: n/a
Valerian,

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

Eliyahu

"Valerian John" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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" <re*************@monarchmed.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
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" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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



Nov 18 '05 #6

P: n/a
Eliyahu:

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

Val
"Eliyahu Goldin" <re*************@monarchmed.com> wrote in message
news:eW**************@TK2MSFTNGP10.phx.gbl...
Valerian,

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

Eliyahu

"Valerian John" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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" <re*************@monarchmed.com> wrote in message
news:Or**************@TK2MSFTNGP10.phx.gbl...
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" <vj***@shentel.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
> 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
>
>



Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.