I was successful in my first attempt at exporting a gridview to an excel file.
However the next attempt, has a gridview with paging, sorting and a footer.
I found code to turn off the paging and sorting. It also shows another databind call, even with this I still get the error: RegisterForEventValidation can only be called during Render();
Can a gridview with a footer also be causing this error? Below is my code:
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Me.EnableViewState = False
Dim oStringWriter As New System.IO.StringWriter
Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
' turn off paging
GridView1.AllowPaging = False
GridView1.AllowSorting = False
' turn the paging on again
GridView1.AllowPaging = True
GridView1.AllowSorting = True
View Complete Post