ListBox clientside changes not reflecting on serverside code

L

Luis Ferrao

Hi,

I have some code that looks like this:

-- CODE ----------------------------
Public Class NodeEditor
Inherits System.Web.UI.Page

Protected WithEvents ChildList As System.Web.UI.WebControls.ListBox

Private Sub Page_Load(...) Handles MyBase.Load
'nothing relevant to the ChildList
End Sub

Private Sub SubmitButton_Click(...) Handles SubmitButton.Click
Dim count As Integer = ChildList.Items.Count
End Sub
-- CODE ----------------------------

Why is the value of 'count' zero no matter how many elements are added
to the ListBox in clientside jscript code?
In other words, why arent clientside changes being reflected after the
form is posted?

Thanks in advance,

Luis
 
K

Karl Seguin

Luis:
When you add ListItems to a dropdownlist on the SERVER, that information is
persisted in the viewstate. When you select an item, and postback, all the
listitems are re-created from the viewstate, and the selected one is
determined from the value in the Request.Form. Only selected values are
present in REquest.Form which is why the values are initially stored in the
viewstate.

When you don't create any values on the server, obviously there's no values
for the viewstate to persist. when you create them on the CLIENT and select
a value, the listitems are re-created from the viewstate - in this case
there are no listitems in the viewstate. The only information the server
has on postback at this point is the selected value in the shape of
Request.Form...but this isn't even close to enough information to rebuild
it.

Short answer to your question is that it just doesn't work that way.

Karl
 
L

Luis Ferrao

Thanks Karl, this is crystal clear.

Since i have no way of knowing what or how much information is going to
be added, i'll use a text box with coma separated values. The textbox
should be present and persisted in the viewstate at all times.

Once again, thank you for your help.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top