473,549 Members | 2,628 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
6 6497
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******** ********@TK2MSF TNGP12.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
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******** ********@TK2MSF TNGP12.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
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=docume nt.getElementBy Id('ListBox1');
var oOption = document.create Element("OPTION ");
oOption.text="T est";
oOption.value=" Test";
oListBox.add(oO ption);
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******@hotma il.com.nospam> wrote in message
news:uy******** ******@TK2MSFTN GP09.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******** ********@TK2MSF TNGP12.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
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.co m> wrote in message
news:Or******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP12.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
Valerian,

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

Eliyahu

"Valerian John" <vj***@shentel. net> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.co m> wrote in message
news:Or******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP12.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
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.co m> wrote in message
news:eW******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP09.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.co m> wrote in message
news:Or******** ******@TK2MSFTN GP10.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******** ********@TK2MSF TNGP12.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1785
by: Oleg Leikin | last post by:
Hi Dear .NET experts ! Is it safe to call ListBox.Items.Add() from different threads without using "lock" ? Or should I use "lock" as I used CriticalSection in my MFC application ? Thanks in advance !!! Oleg
3
9054
by: Prasad | last post by:
Hey All, I am having a little trouble with the ListBox's Items collection property. I am populating the ListBox with data contained in an SQL table using SQLDataAdapter and DataSet. I have set the "DataSource", "DisplayMember", and "ValueMember" properties of the ListBox correctly like below: lbTechnician.DataSource =...
3
9237
by: Mike | last post by:
Hi lstRight contains the following item "Bart " and myTempDataRow.ToString() returns "Bart " with more spaces, so the lstRight.Items.Contains(myTempDataRow.ToString()); is returning false; so how can I fix this space problem? Thanks
4
11482
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you select, the first one in the listbox is always removed.(The listitem with an index of 0. Box is set to single selection mode) I've looked at...
3
2000
by: Baren | last post by:
Hi! I have a generalized Stored Procedure to get the listbox items in a datareader.Then i am binding the datareader to the listbox. For different pages and different conditions i need to hide and show some the items returned by the datareader. Can anyone help me out to solve this issue. Thanks in adavnce.
0
2747
by: marcelo | last post by:
Could you help me out here. I need to accomplish this: I need to filter listbox items from by entering some characters to the textbox. But the problem is that items (files that are read from directory) in the listbox has the same name in the beginning, for example '2007_<docNo>_<CustomerName_ItemSold>.doc'. And the information I need to find...
1
8302
by: Refugnic | last post by:
I tried to fill a ListBox with a DataSource pointing to an ArrayList. It all works fine...up to one point. The ArrayList is dynamic, which means the contents of it change, during the course of program use. But instead of Updating the ListBox, virtually nothing happens. The items that were written into the ListBox during the first run remain...
6
15427
by: kimiraikkonen | last post by:
Hi, I can read from a text file and insert text file's contents into a listbox whose format is line by line using this code: Dim reader As String reader = My.Computer.FileSystem.ReadAllText("c: \bookmarks.txt") Dim strs() As String strs = Split(reader, Environment.NewLine)
1
2060
by: PaulBrains | last post by:
I was trying to sum up all the items of a listbox in Visual Studio 2005. I tried to loop (from 0 to ListBox.Items.Count - 1) as follows For j as Integer = 0 to ListBox.Items.Count - 1 sum = sum + val(ListBox.Items.Item(j)) Next My problem is: the sum variable keeps returning 0, and the ListBox.Items.Item(j) does not...
2
11109
by: gnosys | last post by:
In ASP.Net 1.1 using C#, I'm trying to dynamically change the background colors of certain listbox items based on some criteria. For example:
0
7541
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7734
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7497
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7826
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6065
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5107
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3493
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1960
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
781
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.