问题
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 datagrid 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?
回答1:
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.
来源:https://stackoverflow.com/questions/3420635/datagrid-button-invalid-postback-or-callback