I am trying to save my data that populates the TreeList in a ViewState. When nodes are editted, I want to update their values in the ViewState. But no changes seem to be saved in the ViewState. The Page.SaveViewState method is not even called after an edit or after a tree is expanded (it is only called on first page load).
Why can't I update the Page ViewState from one of the AJAX callbacks from a TreeList? Do I need to do something to allow the ViewState to be changed during postbacks from the TreeList?
Thanks!
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Hi Jay,
The ViewState is not preserved during a callback. This behavior is by design. Please note that a callback's paradigm is to update only a part of the page, to say more specifically, the control initiating a callback is updated. A possible solution to this problem is to add a control to the MS UpdatePanel and set the ASPxTreeList.EnableCallbacks property value to false. The MS UpdatePanel is able to preserve a viewstate during its callbacks.
Thanks,
Plato
In several articles you mentioned saving the data into a ViewState. But I need to be able to edit the data (insert, delete, update rows) as well. Do you have a sample on how to do this without saving the data into a database immediately?
Thanks,
Jay
Hi Jay,
We do not recommend preserving data in the ViewState. In the ViewState you only can store a string, and it can be rather difficult to serialize / deserialize a datasource to / from a string. It is better to store data in the Session. The example, linked to this message, shows how this works for the ASPxGridView. The same approach should work properly with the ASPxTreeList.
Thanks,
Plato
Unfortuantely, the Session object has been disabled on our server environment (we support parallel server farms), so we cannot use the Session object. Additionally, the same user can have the same page open pointing to different objects in multiple windows, so the Session object could not be used (each window would incorrectly "share" the session object).
Our class (basically a List of a simple class), is easily serializable, and is easily placed into the ViewState.
Are you saying that this control will not support using a ViewState to store the data?
I was thinking about the Session object, and I really wanted to clarify my understanding, and the potential disasterous results of using the session object on a page for this purpose. If my understanding is correct, the session object is shared for all browser windows that a user opens to the same server. What this would mean is that if a user opens a page that has the ASPxTreeList storing the data in the session object (perhaps it is viewing/editing some object it retrieves from a back-end database), and then opens the same page for a different back-end object … both pages will be using the same Session object data, and the user would see the same data in both windows.
I have read several FAQs / articles on your site that says to use the Session object, but I did not see any warning that it would not work correctly if the user opens multiple windows. If my understanding is correct, this approach is extremely dangerous, and people must be absolutely careful to understand the limitations and dangers. Perhaps certain uses would be OK, but I would imagine that most uses would fail with multiple windows.
Is my understanding correct? Would using the Session object (as opposed to using a ViewState object) result in errors (in the data) if the user opens the same page multiple times?
Thanks for the clarification.
One other note …
"A possible solution to this problem is to add a control to the MS UpdatePanel and set the ASPxTreeList.EnableCallbacks property value to false"
I tried this, and I had 1 problem – I wrapped the ASPxTreeList into a div so that can show scroll bars for long lists. When it is wrapped into an AJAX panel, it loses the scroll position inside the div on every postback (eg clicking on the plus key).
Is there any other way to support vertical scroll bars, and yet maintain scroll position when EnableCallbacks is set to false?
Thanks!
Hi Jay,
Generally, the ASPxTreeList is a visual control and it can be bound to any data source object which supports the IList or IEnumerable interfaces. The ASPxTreeList just reads data from the DataSource and represents it to the client. It does know where data is stored and should not know about this. This is the task of the DataSource. So, if you wish to store data in the ViewState, you may do this. In this case, you should serialize / deserialize your datasource to / from a string. Also, please note that the ViewState is stored in a hidden field and is sent to the client and back to the server. So, this approach will make your application slower on the client side, since the page will be loaded more slowly. I think that the best solution to this problem is to fetch data to the server at every request, and post data to the DB as well.
Thanks,
Plato
Yes, I would like to use the ViewState to serialize my datasource. But the problem is that the ViewState is not saved during postbacks such as when I edit or delete a row. Is there a way to "tell" the ASPxTreeList to allow the ViewState to be saved? Otherwise, I do not see how the ViewState can be used.
Thanks.
… the reason I cannot just save the data to the database on each postback (ajax call), is that I need to put a cancel on the page to cancel all pending updates. The data should only be saved back to the database when the OK button is hit. If the user cancels, or does not hit "ok", none of their edits should be saved.
Hi Jay,
The ViewState is stored in a hidden field which is rendered in the page's header. During a callback, the client receives the content of the control which initiated this callback. ViewState is not sent to the client (since it sits in the header) and our controls cannot embed it in the response and then update the corresponding hidden field. A possible solution is to set the ASPxTreeList's EnableCallbacks property value to false, and use the ASPxTreeList on the MS UpdatePanel. It will be able to intercept a TreeList's postbacks and "convert" them to callbacks. It is also able to update the ViewState.
Thanks,
Plato