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

RadGrid State preserving on postback

8 Answers 1454 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Grendizer
Top achievements
Rank 1
Grendizer asked on 29 Apr 2009, 02:55 PM
Hello,

I would need some clarification on state preservation of the RadGrid

As indicated here the grid should preserve grouping when view state is enable.

I use the last release a simple grid with a dummy data-source taken from Persist Groups Expanded State on Rebind sample.

<telerik:RadGrid ID="RadGrid1" runat="server"   
    AllowSorting="true" ShowGroupPanel="True"                 
    OnNeedDataSource="RadGrid1_NeedDataSource" 
   AllowMultiRowSelection="false" 
   Skin="Vista" 
    > 
    <ClientSettings AllowDragToGroup="True" EnablePostBackOnRowClick="true">  
    </ClientSettings> 
    <MasterTableView GroupLoadMode="Server" > 
        <GroupByExpressions> 
            <telerik:GridGroupByExpression> 
                <GroupByFields> 
                    <telerik:GridGroupByField FieldName="Group" /> 
                </GroupByFields> 
                <SelectFields> 
                    <telerik:GridGroupByField FieldName="Group" /> 
                </SelectFields> 
            </telerik:GridGroupByExpression> 
        </GroupByExpressions> 
    </MasterTableView> 
</telerik:RadGrid> 
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 

protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
    {  
 
        DataTable tbl = new DataTable();  
        DataColumn col = new DataColumn("ID");  
        col.DataType = typeof(int);  
        tbl.Columns.Add(col);  
        col = new DataColumn("Name");  
        col.DataType = typeof(string);  
        tbl.Columns.Add(col);  
        col = new DataColumn("Group");  
        col.DataType = typeof(string);  
        tbl.Columns.Add(col);  
 
        int size = 15;  
        int maxLen = size.ToString().Length;  
        for (int i = 1; i <= size; i++)  
        {  
            tbl.Rows.Add(new object[] { i, "Name" + i.ToString("D" + maxLen), "Group" + i % 5 });  
        }  
        RadGrid1.DataSource = tbl;  
    }  
 
    protected void Button1_Click(object sender, EventArgs e)  
    {  
       /*RadGrid1.Rebind();*/ 
    } 

Then
- with grouping (server side) the postback button will keep state as Rebind command has been commented out, but if Rebind command is activated the collapsed section information get lost
- with grouping ( still server side ) acting on the sorting reset the collapsed section as well.
- with grouping (client side) selected row and collapsed area are lost as well.

On key Feature page the #19 provide us the following : "an unique feature of Telerik RadGrid is the ability to preserve its appearance, group-by state, sorting, current page, edit or selected state, and resizing after postbacks"

Some links concerning previous built are available like Client-Side Row Selection Persisted With PagingPersist Groups Expanded State on Rebind  .. but don't know if they are still valuable for the last release.

Could someone clarify the situation on what is available / built-in and what should be done manually or not, in order to preserve ALL state, in case of server side and client side usage. ( a kind of matrix would be fine ... plus some links on how to do stuff manually, pointing to avaliable threads like the two above.) A grid demo including all available stuff would be nice as well.

Many thanks in advance for your time.

8 Answers, 1 is accepted

Sort by
0
Todd Anglin
Top achievements
Rank 2
answered on 04 May 2009, 08:32 PM
Hello Sebastien-

In general, most of the Grid's state is persisted across post backs. For example:

  • Grouping, Sorting, Paging, Page Size, Selected Item, and Filtering states are all automatically persisteed across post backs
  • Expand/Collapse of Groups is persisted when a postback is caused by selecting a new item, changing group expand/collapse settings, or when a general page postback occurs

In fact, the only times I think you lose the grouping expand/collapse state is when you either A) change the sorting of the grid, or B) change the page. If the page is just posting back due to some other control event, the expand/collapse state is automatically persisted. This is all true for server-side processing.

For client-side processing, the story is a little different as a PostBack is wiping-out the incremental changes that have been made on the client. In general, I would advise that you avoid doing full page PostBacks when using client-side binding and instead only update sections of the page with UpatePanels or client-side script. That is the simplest way to avoid problems with client-side binding/rendering.

Hope this helps. Let me know if you have any specific trouble.
-Todd
0
Grendizer
Top achievements
Rank 1
answered on 05 May 2009, 01:37 PM
Hello Todd,

Thanks for the clarification, and for providing such detailed answer.

Best Regards.

Sebastien
0
TonyG
Top achievements
Rank 1
answered on 10 May 2009, 12:21 AM
As indicated in other threads, my grid is not preserved in ViewState, so I'm rebinding as required before events fire so that there is data available on which to operate.  I'm also finding that when events are fired on other controls, the grid doesn't retain it's SelectedIndex value, and no matter where I set it, it doesn't stick.

Todd, you mentioned using an UpdatePanel.  My controls are in a usercontrol in a content page for a master page.  I have my manager proxy set, pretty much so that any control event will update all other controls and asp:Panels that contain them.  It seems like major overkill and yet I'm still not getting the desired effect.

So what might be preventing the grid from preserving state?
When you suggest using an UpdatePanel, I trust a managerproxy and ajaxsettings should be equivalent?
(Really second-guessing myself here but I'll be happy if I'm missing something stupid) Is there some PreserveViewState option that's required that I might be missing in controls or a panel or user control, or master page?
Thanks
0
Yavor
Telerik team
answered on 12 May 2009, 12:53 PM
Hello TonyG,

When you have turned off the viewstate, and rebinding the control, all data such as selected items will be lost. One possible option in this case would be to preserve and restore the selection when the control is rendered. Other than that, it cannot automatically persists these values/state.

Regards,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Roger
Top achievements
Rank 1
Veteran
answered on 02 Jul 2014, 05:03 PM
  • Expand/Collapse of Groups is persisted when a postback is caused by selecting a new item, changing group expand/collapse settings, or when a general page postback occurs

I have RadGrid with EnableViewState=true, GroupByExpressions and EntityDataSource (declaratively bound). Expand/collapse state of groups are not persisted between postbacks. It is independent from A) and B).

Does anybody have same problem?

0
Maria Ilieva
Telerik team
answered on 07 Jul 2014, 11:15 AM
Hello Roger,

Please note that RadGrid does NOT manage the state for the following features when its EnableViewState property is set to false:

  • Custom edit forms (user control or form template)

  • Value of the filter input control, however, the filter expression is persisted and so the filtered results.

  • GroupByExpressions are not persisted on Rebind and postback.

  • Expanded state of items in hierarchy. This basically means that you could not use more than one level of hierarchy, unlesss you save the expanded settings manually.

If you would like to retain the expanded state of items or server-side selection with ViewState disabled, you may consider using the approach depicted in this code library entry (applicable for explicit rebinds or ViewState switched off) . An alternative solution would be to turn on the ViewState of the grid and optimize its performance by using RadCompression and its page adapters as explained in this article.

I hope this helps.


Regards,
Maria Ilieva
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.

 
0
Roger
Top achievements
Rank 1
Veteran
answered on 07 Jul 2014, 12:27 PM
Hi Maria

Thanks for the explanations. But I was mentioning that EnableViewState is enabled. It does not apply to my problem.

Regards,
Roger
0
Maria Ilieva
Telerik team
answered on 10 Jul 2014, 10:23 AM
Hello Roger,

Excuse me for missing the ViewState settings in your last post.

In case this is not your scenario and the problem appears with enabled ViewState it will be best if you open a separate regular support ticket and provide additional information for the exact scenario you are implementing. Thus we could further investigate on your case and provide straight to the point solution.

Regards,
Maria Ilieva
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
Grendizer
Top achievements
Rank 1
Answers by
Todd Anglin
Top achievements
Rank 2
Grendizer
Top achievements
Rank 1
TonyG
Top achievements
Rank 1
Yavor
Telerik team
Roger
Top achievements
Rank 1
Veteran
Maria Ilieva
Telerik team
Share this question
or