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

Avoiding Viewstate Errors when Changing the Grid with SharePoint Web Part Settings

1 Answer 50 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ted
Top achievements
Rank 1
Ted asked on 26 Nov 2014, 08:17 PM
We have a challenging problem that we need help with.   We are implementing a custom grid control
and using web part settings to enable/disable certain columns and buttons in
the control.   The issue is that when you
click to apply the web part settings and enable a column for example, the grid
does not change.    Furthermore, when you
refresh the page you get a Failed to Load Viewstate error.

 

The grid is created as a custom Sharepoint Web Part and then
adding the grid in CreateChildControls programmatically.

 

However, we are having the following issue with applying web
part settings that change the grid layout.

 

If you go into the web part settings for the grid and change
a setting that changes the grid layout (e.g. display edit button column) it
causes a Failed to Load Viewstate error on refresh.   If you close the browser and reopen it, it
works fine (edit column is displayed).  
Since the control layout is saved in the viewstate, this error makes
sense.  However, the question we need
help with is how to refresh the page programmatically when any web part setting
is changed so that the changes to the grid display.

 

The Web Part Editor fires an ApplyChanges event when you
click Ok or Apply.   This is what saves
the changes.   However, if we put a page
redirect in this method to refresh the page, then the web part setting changes
are not saved. 

 

What I need is a way first to detect whether any changes
were made to the web part settings and then if changes were made, to refresh
the page including the viewstate. 

 

If you look at the page lifecycle events below, this
detection would have to happen somewhere after ApplyChanges and somewhere
before the page is rendered.  Maybe in
SyncChanges?

 

 

 

Steps to Simulate Error

 

1. Create a simple grid in Sharepoint by inheriting from a
grid component

2. Create a web part setting that enables/disables one of
the columns.

3. Select to enable the column and then click Apply and then
Ok

 

Event Firing Sequence During Issue

 

Checked Enable Edit Column and then clicked Apply in the Web
Part Editor pane

SPGridWebPart Constructor <- This causes a postback and
it goes through the page lifecycle again

Event OnInit

Event CreateChildControls

Event SPGridEditor:CreateChildControls

Event Page Load

Event grid_Load

Event SPGridEditor:ApplyChanges <- The change to the edit
column enabled setting is done here, but after the child controls are already
created

Event SPGridEditor:SyncChanges

SPGridWebPart Constructor

Event Page Load Complete

Event OnPreRender

Event grid_PreRender <- Page is rendered without the edit
column even though box is checked to show the edit column

Event SPGridEditor:RenderContents

Clicked Ok in the web part editor pane

SPGridWebPart Constructor

Event OnInit

Event CreateChildControls

Failed to load viewstate error

 

Code Snippets Showing the Web Part Setting for
Enabling/Disabling Edit Column

 

        const Boolean c_boolEnableEditColumn = true;

        private
Boolean _boolEnableEditColumn;

       
[Category("Custom - Basics"),

       
Personalizable(PersonalizationScope.Shared),

       
WebBrowsable(true),

       
DefaultValue(true),

        WebDisplayName("Enable
Edit Column"),

       
WebDescription("Show an edit column with an edit button for each
item")]

        public Boolean
boolEnableEditColumn

        {

            get {
return _boolEnableEditColumn; }

            set {
_boolEnableEditColumn = value; }

        }

 

 

        public
SPGridWebPart()

        {

                                boolEnableEditColumn
= c_boolEnableEditColumn;

                }

 

 

1 Answer, 1 is accepted

Sort by
0
Marin
Telerik team
answered on 01 Dec 2014, 11:33 AM
Hello Ted,

We have discussed the issue in the support thread you have opened on the same problem. If you have any further questions we can continue the communication there in order to avoid duplicate posts.

Regards,
Marin
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Ted
Top achievements
Rank 1
Answers by
Marin
Telerik team
Share this question
or