This is a migrated thread and some comments may be shown as answers.

Viewstate issue when reordering columns in PreRender

3 Answers 223 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ed
Top achievements
Rank 1
Ed asked on 15 Dec 2008, 06:49 PM
In this thread:

http://www.telerik.com/community/forums/aspnet-ajax/grid/accessing-the-column-collection-for-autogenerated-columns.aspx

I mentioned how I handled reordering columns (often to restore a stored order) in the PreRender when using RadGrid in RadControls for ASP.Net and more recently in RadControls for ASP.Net AJAX.  At the time of that thread, I hadn't quite gotten it working in the AJAX version, but subsequently seemed to get it to work.

However, i am now hitting a problem that I haven't quite put my finger on.  My code in PreRender keeps track of whether or not it actually needed to change the column order (as it loops through the columns in RenderColumns if any needs to be reordered it sets a flag that it did so.)  If the flag gets set, then it does a Rebind of the grid (since otherwise the new order doesn't match the data).

Now I am finding that when I do so, on a subsequent refresh of the page, I get the dreaded:

Failed to load viewstate.  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request.

error.  This ONLY occurs if I reordered and did a Rebind in PreRend.  I'm surmising that there is something in the viewstate loading for RadGrid that expects the column order (and therefore types of the columns) or something related (filter row maybe?) not to have changed as late as the preRender (maybe some other structure in the RadGrid that has viewstate saved as well that could be out of sync if i reorder and rebind in PreRender?)

Anyway, I am still debugging on this, but any sugestions appreciated.  The previously suggested approach of turning off viewstate for this grid is, however, not an acceptable soluytion, so suggesting that doesn't help.  There are many aspects of the grid state that viewstate retains that we cannot sacrifice in terms of end user functionality, nor do we want to reimplement all the viewstate stuff for the grid without viewstate. The core problem i need guidance on is how, with viewstate enabled, I can reorder and rebind my grid safely.

Thanks,

-Ed

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 Dec 2008, 06:12 PM
Hello Ed,

It would be helpful if you send us a simplified working version of your code. It's hard to provide a to-the-point answer without examining your approach locally.

The only recommendation which I can give you now is to try to switch off the viewstate of your columns.
<MasterTableView EnableColumnsViewState="false"...  

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ed
Top achievements
Rank 1
answered on 18 Dec 2008, 06:31 PM
Actually, I found another way around it.

Instead of using the PreRender event, I handle the ColumnsReorder event, do the column order management (and Swapping) there, and most importantly, set e.Cancelled = true since i did the column swapping myself instead of letting RadGrid's event handler do it.

using that approach, and specifically NOT mucking with the column order in PreRender handled the problem.  For the scenario where I am setting the column order upon startup (no user interaction yet), I also just make sure I do the SwapColumns call after binding the grid rather than waiting for PreRender, and again that works fine.

(As i said repeatedly, turning off viewstate is not an acceptable solution to most problems, because lots of what is in viewstate would have to be reimplemented if doing so - not a palatable situation.
0
Monika
Top achievements
Rank 1
answered on 25 Aug 2009, 07:29 AM
Hi

I am using RadGrdi Prerender Event to merge the rows of grid on some logic.
On prerender event I am accessing values from some session object. Sometimes when Session gets expired user does not redirect to SessionOut page but somtimes redirection to session out page happens.
I am not able to replicate the behabviour on local machine.

Is there any clue why session expired is not getting handled on Prerender event.

Thanks
Monika Sharma

Tags
Grid
Asked by
Ed
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Ed
Top achievements
Rank 1
Monika
Top achievements
Rank 1
Share this question
or