Hello there,
I have a UserControl that i am trying to use as edit form for a RadGrid. The UserControl has some controls inside that perform postbacks (such as a RadComboBox changing the value of a RadNumericTextBox on SelectedIndexChanged), however I ajaxified this using a RadAjaxManagerProxy and adding the combobox as initiator and the same combobox and the textbox as updated controls.
In the NeedDataSource handler of the grid, i set the DataSource property with a collection of objects and in the ItemDataBound handler for the grid, if the item is in edit mode, i set some properties of the UserControl, including the one which stores the id of the object to be loaded.
This is the code for the two handlers:
ctrl.Refresh() calls a method inside the UserControl which redraws the inner controls, as they are dynamically added to the UserControl.
When the edit button inside the grid is pressed, putting the row in edit mode, everything works ok and the UserControl is loaded properly. However, let's say i change the selection of a combobox inside the UserControl. As i said, this needs to update a textbox in the same user control according to the new selection. Though the combobox would normally trigger a postback and refresh the whole page, textbox included, as this is ajaxified using the RadAjaxManagerProxy defined inside the UserControl, i would expect only the textbox to be updated and no action performed on the other inner controls or the radgrid having this UserControl as edit form.
What actually happens is that somehow, the NeedDataSource event is fired again, reloading the grid data source, which then triggers a Rebind on the grid, which then goes into ItemDataBound, reassigns the UserControl properties and triggers the ctrl.Refresh() which redraws the inner controls. At this point, the inner controls are re-created according to the initial data, while the ViewState contains the modified data, leading to a mismatch between the saved state and the current state. Bingo, corrupted ViewState error.
What i don't understand is why an ajax request inside the UserControl leads to the containing grid firing its NeedDataSource event. The way I see it (please correct me if i am wrong with this), the ajax request should only update the controls specified in the RadAjaxManagerProxy settings, not the whole grid. Have i made any mistake in approaching this? If so please shed some light on this matter as I have no idea how to get past this.
While browsing the other forum threads, i came across THIS thread, which seems related, though i cannot say for sure it's the same problem i'm experiencing.
I have a UserControl that i am trying to use as edit form for a RadGrid. The UserControl has some controls inside that perform postbacks (such as a RadComboBox changing the value of a RadNumericTextBox on SelectedIndexChanged), however I ajaxified this using a RadAjaxManagerProxy and adding the combobox as initiator and the same combobox and the textbox as updated controls.
In the NeedDataSource handler of the grid, i set the DataSource property with a collection of objects and in the ItemDataBound handler for the grid, if the item is in edit mode, i set some properties of the UserControl, including the one which stores the id of the object to be loaded.
This is the code for the two handlers:
| protected void grdRelated_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
| { |
| grdRelated.DataSource = GetGridDataSource(); |
| } |
| protected void grdRelated_ItemDataBound(object sender, GridItemEventArgs e) |
| { |
| if (e.Item is GridEditFormItem && e.Item.IsInEditMode) |
| { |
| IAssignControl ctrl = e.Item.FindControl(GridEditFormItem.EditFormUserControlID) as IAssignControl; |
| if (ctrl != null) |
| { |
| AssignedProduct assignedProduct = (e.Item as GridEditFormItem).DataItem as AssignedProduct; |
| ctrl.EntityType = "Opportunity"; |
| ctrl.BOId = "86cc5561-d769-4b77-b51e-386e989de0ae"; |
| ctrl.InAssignMode = false; |
| ctrl.AssignedProductID = assignedProduct.UniqueID; |
| ctrl.Refresh(); |
| } |
| } |
| } |
ctrl.Refresh() calls a method inside the UserControl which redraws the inner controls, as they are dynamically added to the UserControl.
When the edit button inside the grid is pressed, putting the row in edit mode, everything works ok and the UserControl is loaded properly. However, let's say i change the selection of a combobox inside the UserControl. As i said, this needs to update a textbox in the same user control according to the new selection. Though the combobox would normally trigger a postback and refresh the whole page, textbox included, as this is ajaxified using the RadAjaxManagerProxy defined inside the UserControl, i would expect only the textbox to be updated and no action performed on the other inner controls or the radgrid having this UserControl as edit form.
What actually happens is that somehow, the NeedDataSource event is fired again, reloading the grid data source, which then triggers a Rebind on the grid, which then goes into ItemDataBound, reassigns the UserControl properties and triggers the ctrl.Refresh() which redraws the inner controls. At this point, the inner controls are re-created according to the initial data, while the ViewState contains the modified data, leading to a mismatch between the saved state and the current state. Bingo, corrupted ViewState error.
What i don't understand is why an ajax request inside the UserControl leads to the containing grid firing its NeedDataSource event. The way I see it (please correct me if i am wrong with this), the ajax request should only update the controls specified in the RadAjaxManagerProxy settings, not the whole grid. Have i made any mistake in approaching this? If so please shed some light on this matter as I have no idea how to get past this.
While browsing the other forum threads, i came across THIS thread, which seems related, though i cannot say for sure it's the same problem i'm experiencing.