Now here in this tutorial, I’ll explain how to solve the RegisterForEventValidation can only be called during Render(); error while exporting the gridview data in asp.net c# vb.net.
In my previous tutorials, I’d explained export all gridview data to word excel text pdf, export only selected rows from gridview to word excel text pdf, print gridview data on print button click and other more cracking tutorials on GridView, Asp.net here.
Error: RegisterForEventValidation In Asp.net
Server Error in ‘/’ Application.
RegisterForEventValidation can only be called during Render();
Description: An unhandled exception occurred during the execution of the current web request.
Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: RegisterForEventValidation can only be called
during Render();
Error Cause:
You might get this error while you are trying to render control to response during gridview data export to word, excel, pdf etc.
Error Solution:
We need to add EnableEventValidation=”false” in @Page directive on the top of the .aspx page.
Following is the sample code to resolve the RegisterForEventValidation error:
AutoEventWireup=”true” Inherits=”ExportToWordExcelPdf.ExportSelectedRowsExamples”
EnableEventValidation=”false” %>