D
David
Using ASP.Net 2.0 and I have identical code for exporting a GridView to
Excel in 2 web sites. One works fine and the 2nd one gives me the error
"RegisterForEventValidation can only be called during Render();"
This error occurs on the line that reads "gv.RenderControl(hw)"
Below is my code. Can anybody give me a clue? Thanks.
Sub SendToExcel(ByVal Source As Object, ByVal E As EventArgs)
Dim gv As GridView = SearchResultsGridView
If gv.Rows.Count.ToString + 1 < 65536 Then
gv.AllowPaging = False
gv.AllowSorting = False
If txtSearchText.Text <> "" Then
SqlvwFileSearch.SelectCommand = txtSearchText.Text
End If
gv.DataBind()
Dim tw As New StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=search.xls")
Response.Charset = ""
EnableViewState = False
gv.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
'gv.AllowPaging = True
gv.AllowSorting = True
gv.DataBind()
lblErrorMsg.Text = ""
Else
lblErrorMsg.Text = "Too many rows - Export to Excel not possible"
End If
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
End Sub
David
Excel in 2 web sites. One works fine and the 2nd one gives me the error
"RegisterForEventValidation can only be called during Render();"
This error occurs on the line that reads "gv.RenderControl(hw)"
Below is my code. Can anybody give me a clue? Thanks.
Sub SendToExcel(ByVal Source As Object, ByVal E As EventArgs)
Dim gv As GridView = SearchResultsGridView
If gv.Rows.Count.ToString + 1 < 65536 Then
gv.AllowPaging = False
gv.AllowSorting = False
If txtSearchText.Text <> "" Then
SqlvwFileSearch.SelectCommand = txtSearchText.Text
End If
gv.DataBind()
Dim tw As New StringWriter()
Dim hw As New System.Web.UI.HtmlTextWriter(tw)
Response.Clear()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", "attachment;filename=search.xls")
Response.Charset = ""
EnableViewState = False
gv.RenderControl(hw)
Response.Write(tw.ToString())
Response.End()
'gv.AllowPaging = True
gv.AllowSorting = True
gv.DataBind()
lblErrorMsg.Text = ""
Else
lblErrorMsg.Text = "Too many rows - Export to Excel not possible"
End If
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As
System.Web.UI.Control)
End Sub
David