views:

29

answers:

1

I have setup a DataGrid with a number of columns and a checkbox and column at the end of the row.

I am also changing the layout of the datagrid on the OnItemCreated event which changes the layout of the datagrid by expanding the rows with the "Rowspan" attribute and remove the extra columns and controls where they are no longer required.

The original datagrid layout was setup like this:

___________________________________________
| 1 | Employee Name | 01/08/10 |[] |[SAVE]|
| 1 | Employee Name | 02/08/10 |[] |[SAVE]|
___________________________________________
| 2 | Employee Name | 01/08/10 |[] |[SAVE]|
___________________________________________
| 3 | Employee Name | 04/08/10 |[] |[SAVE]|
| 3 | Employee Name | 05/08/10 |[] |[SAVE]|
| 3 | Employee Name | 06/08/10 |[] |[SAVE]|
___________________________________________
| 4 | Employee Name | 03/08/10 |[] |[SAVE]|
___________________________________________

And now it looks like this with the rows expanded, the controls removed and the dtagrid columns deleted...

___________________________________________
| 1 | Employee Name | 01/08/10 |[] |[SAVE]|
|   |               | 02/08/10 |   |      |
___________________________________________
| 2 | Employee Name | 01/08/10 |[] |[SAVE]|
___________________________________________
| 3 | Employee Name | 04/08/10 |[] |[SAVE]|
|   |               | 05/08/10 |   |      |
|   |               | 06/08/10 |   |      |
___________________________________________
| 4 | Employee Name | 03/08/10 |[] |[SAVE]|
___________________________________________

The page displays when opened, and the paging control works as expected each time a user clicks on a page number.

However, when I click on the [SAVE] button for a particular employee, an error message shows a message similar "Invalid Postback or Callback". I understand that this is a result of the controls and columns that I have removed in the datagrid and the event validation does not match the orignal rendered items.

I do not want to remove the EnableEventValidation because it is a security issue.

I know I have to use the Render method to fix any changes that I have made before the page is displayed, but how do I resolve this postback issue?

A: 

Ok, lets see where the error comming from.

The GridView is use the __DoPostBack() javascript call and have no input by him self. So by him self is not send any input data from other cells.

Now I think that you do not have made custom DoPostBack calls - right ?

The second point that there is a validation is on ViewState Data.

Is by any change to use any UpdatePanel and in the middle you make any update that change this ViewState ?

What I suggest you to try is to send EnableViewState="false" on your GridView To see if you still get this error. This is not affect you because GridView in every update re-read the data that needs to created.

And the second point that you need to check, is the point that you change your data and afect the view state. Maybe by place it in other point solve the issue. From example if you have it on Page_Load maybe you need to move it on PageInit - or vise versa.

Hope this help.

Aristos
Hi Aristos,Yes, I do have the datagrid within an update panel, and have now disabled the EnableViewState. The button works correctly now, and I am able to read the values of the checkboxes as expected.However, the page numbering resets back to page 1, regardless of which page I am on. How do I pick up the page number if I am unable to retrieve the value from the datagrid now that the view state is removed?Thanks.
laughing chocolates
@laughing The fail to keep the page have to do with the point that you have place to read the data - The point that you do the Bind() and set the data on datagrid. You have place that after the pager, so its lose it. Change the point that you set the data on datagrid, move it for example on pageinit and check it out. And probably this is the problem from the beginning.
Aristos
I have changed the location where I have rebind the data and the datagrid works as expected.
laughing chocolates