Losing the State of an ASP Listbox after postback for UpdatePanel

J

John Kotuby

Hi all,

I have an ASP.NET 2.0 page that uses 6 controls all within an UpdatePanel so
that only parts of the page are updated upon postbacks. maybe I have
configured something wrong.

When the page first loads, the listbox is empty. I am adding OPTION elements
to the listbox using clientside javascript. I understand that this only
changes the Document object model in memory and that the changes cannot be
seen using View Source in the browser.

I use a postback to refresh another control with new items which the user
can then (supposedly) select from to add to the listbox. However, during any
postback, the listbox comes back empty. I am being very careful to not run
any of the initializing code that usually runs on first load of the page.
That is why I am perplexed by the apparent loss of state.

Is this occurring because I am loading the listbox using Javascript? Or
would this happen even if the listbox was pre-loaded with items upon initial
page load. I suppose that is easy enough for me to test.

I am guessing it has something to do with the Update Panel that holds all
the controls.

I am thinking of capturing the InnnerHtml of the listbox and saving it to a
hidden field and then using that to restore the state of the listbox between
postbacks, but that seems rather cludgy as a workaround.

Does anyone have a suggestion for me (besides finding another occupation)?
Is there some attribute I must set in the update panel or the control
itself?

Thanks to all...
 
B

bruce barker

when an update panel postsbacks, its innerhtml is replaced by the
server's response. you should pass the option info in a hidden field, so
the server can reconstruct the list.

-- bruce (sqlwork.com)
 
J

John Kotuby

Thank's Bruce,

Your insight is extremely helpful.
Since I am constructing the OPTION elements with javascript I can at the
same time save the Text portion of the ListItems in comma delimited fashion
to one hidden field and the Value parts in a similar fashion to another
field, then process the parallel arrays on the server.
Of course that would preclude the presence of comma's in either the Text or
Value portion.

Sometimes it takes input from another brain to make the light go on.

On the other hand, if I should save the entire clientside HTML contents in a
hidden field I would have to figure a way to parse it.

Unless a Javascript event fires after receipt of the panel update? Like
Onload? Then if the HTML persists in the Hidden field I can just stuff it
back into the control clientside after the callback completes.

BTW... I found out if I add even one Option element at a time to the ListBox
from the Server (during processing of the callback), the contents of the
Listbox persists even after subsequent callbacks. So it appears that Option
elements (ListItems) added (or removed) server-side persist through
subsequent callbacks. Only if those changes are made via the DOM on the
client-side do they Not persist. Interesting.

Your help is much appreciated.
 

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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top