Tutorial :DataExport to Excel Error



Question:

Hi I am trying Export data to excel sheet from GridView but having this error.

RegisterForEventValidation can only be called during Render();

Here is my code

        Dim attachment As String          attachment = "attachment; filename=Contacts.xls"          Response.ClearContent()          Response.AddHeader("content-disposition", attachment)          Response.ContentType = "application/ms-excel"          Dim myStringWriter As New IO.StringWriter          Dim myhtmlStringWriter As New HtmlTextWriter(myStringWriter)          GridView1.RenderControl(myhtmlStringWriter)          Response.Write(myStringWriter.ToString)          Response.End()  

Thanks


Solution:1

You can do this in the web.config file but in this case the eventValidation will be turned off for all the pages.

or you can do this in the Page directive which will turn off the validation for a single page.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »