Tracking State Using ASP.NET AJAX / ICallbackEventHandler

I'm having a stateful issue on an ASP.NET AJAX page. Short version. I need to somehow refresh the ViewState page after the async callback has been executed to reflect any change in the state of the server created during the asynchronous call.

This seems to be a common problem, but I will describe my scenario to help explain:

I have a grid-like control that has some JavaScript enhancements, namely the ability to drag columns and rows. When a column or row is deleted to a new position, the AJAX method is called to notify the server part of the control and fire the corresponding server event ("OnColumnMoved" or "OnRowMoved").

ASP.NET AJAX causes the entire page to be sent as a request by default. Thus, the page goes through the full life cycle, the viewstate is saved, and the state of the control is restored before the RaiseCallbackEvent method is called.

However, since the AJAX call does not refresh the page, the ViewState reflects the original state of the control even after moving a column or row. Thus, the second time the client-side action occurs, the AJAX request is sent to the server, and the page and control are created again to reflect the first state of the control, and not the state after moving the first column or row.

This problem has many consequences. For example, if we have an action on the client side / AJAX to add a new element to the grid, and then the line is dragged, the grid is created on the server side with one fewer elements than on the client side.

And finally, and most seriously for my specific example, the actual data source object we are working on is stored on the ViewState page. This was a constructive solution that allows you to save a copy with saved states of managed data that can be transferred to the database after many manipulations or discarded if the user backs down. It is very difficult to change.

So, again, I need the ViewState page to be refreshed in the callback after the AJAX method is run.

+7
ajax viewstate asp.net-ajax
source share
5 answers

If you still move the ViewState, you can also use the UpdatePanel. Its partial postback will automatically refresh the ViewState page.

+1
source share

Blog Post: Fine-tuning ICallbackEventHandler and Viewstate . It seems that the author refers to the situation in which you experience:

So, when using ICallbackEventHandler, you have two hurdles to overcome in order to update state management for callbacks. Firstly, it is a read-only viewing issue. The other actually logs the changes made by the user to the page before starting the callback.

See the blog post for suggestions on how to resolve this issue. Also check out this forum post , which also discusses the same issue.

0
source share

I really found both of these links that you provided, but as already noted, they just describe the problem, not solve it. The author of the blog post offers a workaround using a different ViewState provider, but unfortunately this is not possible in this case ... I really need to leave the data only to ViewState and just connect to what is done outside the box.

0
source share

I found a pretty elegant solution with Telerik RadAjaxManager . It works very well, in fact, you register every control that can refer to the postback, and then register every control that should be redrawn after postback runs asynchronously. RadAjaxManager will update the DOM after asynchronous postback and rewrite ViewState and all affected controls. After glancing at Reflector, it looks a bit shredded under the hood, but it is suitable for my purposes.

0
source share

I don’t understand why you use a special control for this when the built-in ASP.NET AJAX UpdatePanel does the same.

It just adds more complexity, gives you less support, and makes it harder for other users to work with your application.

0
source share

All Articles