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

[Solved] Javascript error on grouping

1 Answer 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre-Antoine
Top achievements
Rank 1
Pierre-Antoine asked on 02 Dec 2008, 09:32 AM
Hello everyone,

I bind my radgrid with an object.
I set the grid in the code-behind (Columns + options of the grid in the Page_Load in an "if(!isPostBack)").
if (!IsPostBack) 
            { 
                RecordKeepingGrid.ShowGroupPanel = true; 
                RecordKeepingGrid.GroupingEnabled = true; 
                RecordKeepingGrid.AllowPaging = true; 
                RecordKeepingGrid.AllowSorting = true; 
                RecordKeepingGrid.AllowFilteringByColumn = true; 
                RecordKeepingGrid.AutoGenerateColumns = false; 
                RecordKeepingGrid.PagerStyle.Mode = GridPagerMode.NumericPages; 
                RecordKeepingGrid.PageSize = 20; 
 
                GridBoundColumn boundColumn2 = new GridBoundColumn(); 
                RecordKeepingGrid.MasterTableView.Columns.Add(boundColumn2); 
                boundColumn2.UniqueName = "FieldNameRK"; 
                boundColumn2.DataField = "Field.Name"; 
                boundColumn2.HeaderText = "Field Name"; 
                boundColumn2.AllowFiltering = true; 
                boundColumn2.AllowSorting = true; 
                boundColumn2.AutoPostBackOnFilter = true; 
                boundColumn2.Groupable = true; 
                boundColumn2.Reorderable = true; 
 
                GridBoundColumn boundColumn = new GridBoundColumn(); 
                RecordKeepingGrid.MasterTableView.Columns.Add(boundColumn); 
                boundColumn.UniqueName = "StartDateRK"; 
                boundColumn.DataField = "startDate"; 
                boundColumn.HeaderText = "Start Date"; 
                boundColumn.DataType = Type.GetType("System.DateTime"); 
                boundColumn.AllowFiltering = true; 
                boundColumn.AllowSorting = true; 
                boundColumn.AutoPostBackOnFilter = true; 
                boundColumn.Groupable = true; 
                boundColumn.Reorderable = true; 
 
                GridBoundColumn boundColumn3 = new GridBoundColumn(); 
                RecordKeepingGrid.MasterTableView.Columns.Add(boundColumn3); 
                boundColumn3.UniqueName = "TypeOperationRK"; 
                boundColumn3.DataField = "operation.typeOperation.name"; 
                boundColumn3.HeaderText = "Operation Type"; 
                boundColumn3.AllowFiltering = true; 
                boundColumn3.AllowSorting = true; 
                boundColumn3.AutoPostBackOnFilter = true; 
                boundColumn3.Groupable = true; 
                boundColumn3.Reorderable = true; 
 
                GridBoundColumn boundColumn4 = new GridBoundColumn(); 
                RecordKeepingGrid.MasterTableView.Columns.Add(boundColumn4); 
                boundColumn4.UniqueName = "OperationNameRK"; 
                boundColumn4.DataField = "operation.name"; 
                boundColumn4.HeaderText = "Operation Name"; 
                boundColumn4.AllowFiltering = true; 
                boundColumn4.AllowSorting = true; 
                boundColumn4.AutoPostBackOnFilter = true; 
                boundColumn4.Groupable = true; 
                boundColumn4.Reorderable = true; 
 
                GridBoundColumn boundColumn5 = new GridBoundColumn(); 
                RecordKeepingGrid.MasterTableView.Columns.Add(boundColumn5); 
                boundColumn5.UniqueName = "AreaRK"; 
                boundColumn5.DataField = "area"; 
                boundColumn5.HeaderText = "Area"; 
                boundColumn5.AllowFiltering = true; 
                boundColumn5.AllowSorting = true; 
                boundColumn5.AutoPostBackOnFilter = true; 
                boundColumn5.Groupable = true; 
                boundColumn5.Reorderable = true; 
            } 

And this is my method to bind my grid (I hide some private code):
long[] fieldsSelected = [..........].getFields(); 
 
            [.............................] 
            List<OR[....]> lstRk = new List<OR[....]>(); 
             
            if (fieldsSelected.Length != 0) 
            { 
                foreach (long id in fieldsSelected) 
                { 
                    foreach (OR[....] ork in rs.getR[....]ByIdField(id)) 
                    { 
                        lstRk.Add(ork); 
                    } 
                } 
                MyGrid.DataSource = lstRk; 
                MyGrid.DataBind(); 
            } 
 
            MyGrid.DataBind(); 
I call this method in the Page_Load and when the fieldsSelected variable change (to update the grid).

When I group my data and I want to collapse them or sorting the group item, I've got a Javascript Error :
Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation. 

I try to put the EnableEventValidation at true but nothing change. If I put it at false, there's no error but nothing happened.

Do you have a solution to my problem.

Thanx.

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 03 Dec 2008, 10:03 AM
Hello Pierre-Antoine,

I reviewed the code, and noticed that you are setting the datasource for the grid, and directly calling databind(). Please, keep in  mind that this is not a recommended approach. To make sure the control behaves as expected, please use either the NeedDataSource event handler, or a datasource object. This example demonstrates one possible approach.

Greetings,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Pierre-Antoine
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or