Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ListBox items changed client-side are not available server-side

Reply
Thread Tools

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

 
 
Valerian John
Guest
Posts: n/a
 
      05-15-2004
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


 
Reply With Quote
 
 
 
 
Ashish M Bhonkiya
Guest
Posts: n/a
 
      05-16-2004
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" <(E-Mail Removed)> wrote in message
news:%23kOcm$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-16-2004
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" <(E-Mail Removed)> wrote in message
news:%23kOcm$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Valerian John
Guest
Posts: n/a
 
      05-16-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%23kOcm$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Valerian John
Guest
Posts: n/a
 
      05-16-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%23kOcm$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-17-2004
Valerian,

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

Eliyahu

"Valerian John" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:%23kOcm$(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Valerian John
Guest
Posts: n/a
 
      05-17-2004
Eliyahu:

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

Val


"Eliyahu Goldin" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Valerian,
>
> Have a look at
> http://www.metabuilders.com/Tools/DynamicListBox.aspx
>
> Eliyahu
>
> "Valerian John" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > news:%23kOcm$(E-Mail Removed)...
> > > > 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
> > > >
> > > >
> > >
> > >

> >
> >

>
>



 
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
copy ListBox items to anoher listbox Tomas ASP .Net 1 08-12-2008 08:22 AM
unable to retrieve listbox items on postback , items moved usingjavascript between 2 list boxes (source and target ) divya ASP .Net 1 05-28-2008 05:27 AM
Listbox move multiple selected items to second listbox K B ASP .Net 2 01-08-2007 11:16 AM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
add items from one listbox to other listbox from javascript mc Javascript 0 12-02-2003 08:23 PM



Advertisments