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

ListBox clientside changes not reflecting on serverside code

P: n/a
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Luis Ferrao" <lf*@undisclosed.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 19 '05 #2

P: n/a
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.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.