Using callback, I fill dorpdownlist without postback but it gets empty when a postback is executed

F

Fabio Mastria

Hi all!

In a my simple project I use callback to fill a dropdownlist with xml data
returned by a web service, based on a value which is input via another
dropdownlist.

NOTE: I can't use ajax/atlas.

Using javascript and callback all works... but if I press a button or any
event that raise a postback, the dropdownlist that I fill gets empty!

This also if I set its EnableViewstate property to false.

Someone can help me?

Thank you and regards
F.
 
P

Peter Bromberg [C# MVP]

The reason why ViewState isn't working for you is that you are populating the
dropdownlist in the browser with client script. Since there is no postback
event from this, nothing gets stored in Viewstate. So in order to handle this
you would need to repopulate your dropdown if there is a postback. The server
- side code has no knowledge of the <option ..> elements that you've put into
the control client - side.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 
M

Milosz Skalecki [MCAD]

Howdy,

I don't think it matters as he populates drop down list on the client side
using callback (XMLHttpRequest) AJAX, so the information is not persited in
viewstate, the only information being sent back to the server with HTML form
is selected value. He'd have to either serialize values to hidden field and
deserialize it on the aspx page and populate the drop down list, or populate
drop down after every postback on the client side. Fabio if you need more
explanation please don't hesitate to let us know.

Regards
 
F

Fabio Mastria

Peter said:
The reason why ViewState isn't working for you is that you are
populating the dropdownlist in the browser with client script. Since
there is no postback event from this, nothing gets stored in
Viewstate. So in order to handle this you would need to repopulate
your dropdown if there is a postback. The server - side code has no
knowledge of the <option ..> elements that you've put into the
control client - side. -- Peter

OK Peter it is clear... but how I can recover the data used to fill the
dropdownlist in the previous roundtrip?

I someone want, I can send via mail the entire project (visual studio 2005).
I fail continuously

don't know what to do...

in the callback functions, If i fill the dropdownlist or not, it's the same,
because callback doesn't affect the viewstating process.

help :/

thank you
 
Joined
Jan 30, 2008
Messages
1
Reaction score
0
Use a hidden textbox to store selected value of the dropdown. U need to store using client script.

When postback happens generate the dropdown in the backend and then
select the value using the hidden textbox value.
 

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,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top