ListBox populated with Javascript shows no members upon Callback

J

John Kotuby

Hi all,

I was wondering if what I am seeing is to be expected or maybe I'm setting
things up wrong with the Update Panels. I am programming in VS 2008 with VB.

I have a page with multiple update panels. At the bottom of the page I have
an update panel with UpdateMode="Always" where I store hidden fields. I use
them for communication with the server and maintaining state upon Callbacks.
The fields appear to be always Read/Write accessible at the server during
the page callback.

One of the other update panels is set to UpdateMode="Conditional"
ChildrenAsTriggers="false" and I have defined some trigger buttons
(AsyncPostBackTrigger) that are clicked from within JavasScript functions.
There is an asp listbox (Id = "lstSelected") in that panel which I populate
clientside using the JavaScript DOM, depending on what the user selects from
a Grid .

Upon callback with the Trigger defined for the update panel, I discover that
in Page_Load Me.lstSelected.Items.Count = 0. There are no Items found in the
lisbox even though they were clearly there in the Browser document having
been placed there with JavaScript. Is this to be expected that listboxes
populated in this manner show as empty at the server during callback?

I have resorted to populating some hidden fields with delimited strings
representing the contents of the listbox. These are populated at the same
time as the listbox entries are created via JavaScript...but as I said, for
some reason they persist.

Can anyone tell me why I might be seeing this type of behavior?

Thanks for any replies.
 
B

bruce barker

the browser only posts back the selectedValue of a listbox (select), so any
changes done to list are not refected on server. if viewstate is enabled, the
server saves the orginal list in viewstate, and restores the list from this
on postback. as viewstate is encrypted, client code can not modify it.

in you case you should turn viewstate off, store the list data in a hidden
field (updated on the client side, say with json), then in oninit load the
list from the hidden field.

-- bruce (sqlwork.com)
 

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

Top