Geeks With Blogs
Rodney Vinyard - .NET & SQL Developer When all is said and done, more will be said than done

GridView to Excel - prevents 

"RegisterForEventValidation can only be called during Render()"


'---------------------------------------------------------

'aspx

'---------------------------------------------------------

<%@ Page Language="vb" AutoEventWireup="true" enableEventValidation ="false" CodeBehind="AssayList.aspx.vb" Inherits="TestRequest.AssayList" %>

  

'---------------------------------------------------------

'aspx.vb

'---------------------------------------------------------

 Protected Sub ibExcelExport_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibExcelExport.Click

        ExportToExcel("MyReport.xls", Me.gv1)

    End Sub

   

Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)

 

    End Sub

   

Public Sub ExportToExcel(ByVal strFileName As String, ByVal dg As GridView)

        Response.Clear()

        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)

 

        dg.RenderControl(oHtmlTextWriter)

 

        Response.Write(oStringWriter.ToString())

        Response.[End]()

 

    End Sub

Posted on Friday, August 17, 2012 8:13 AM | Back to top


Comments on this post: GridView to Excel - prevents RegisterForEventValidation can only be called during Render();

# re: GridView to Excel - prevents RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
Thanks I will give this a try
Left by Sandra Moebel on Oct 18, 2012 8:23 AM

# re: GridView to Excel - prevents RegisterForEventValidation can only be called during Render();
Requesting Gravatar...
I can't solve this problem, i am working on MOFLON slip rings
Left by slip ring on Jan 20, 2013 10:09 AM

Your comment:
 (will show your gravatar)


Copyright © Rodney Vinyard | Powered by: GeeksWithBlogs.net | Join free