Question

Consider the following: A text value added to a textbox on the client is added to viewstate on postback (thus the value is still present in the textbox when the page has reloaded).

How come when I move a value from listbox1 to listbox2 via jquery the items in listbox2 are not added to viewstate. (note: the items are selected before POST and the values in listbox2 are available on the server on postback via request.form.getvalues("listbox2").getvalue(index).tostring())

I'm not looking for a work around, I've got that. I'm want to know "why" the listbox2 values are not added. Is there some event being fired for the textbox but not the listbox? Just trying to better understand what's going on. Thanks!

Was it helpful?

Solution

A text value added to a textbox on the client is added to viewstate on postback (thus the value is still present in the textbox when the page has reloaded).

This statement is incorrect. The value of a TextBox server control is preserved across postbacks because the browser sends it in the post data, and on postback the TextBox copies the value from the post data to its Text property. View state is not involved, as you can verify by setting EnableViewState="False". (I'm assuming here that the TextBox is visible and enabled; otherwise, the browser doesn't sent its value in the post data, and view state is required to preserve the value.)

How come when I move a value from listbox1 to listbox2 via jquery the items in listbox2 are not added to viewstate.

For a multi-selection ListBox server control, the browser sends the value of each selected item in the post data. On postback, the ListBox looks at each value in the post data, searches for the corresponding item in its Items collection, and sets that item's Selected property to True. It doesn't add unrecognized values to the Items collection; instead, if event validation is enabled, it throws an "Invalid postback or callback argument" exception. Again, view state is not involved.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top