2009-04-27 81 views
1

嗨我試圖從數據導出到Excel工作表的數據,但有這個錯誤。數據導出到Excel錯誤

RegisterForEventValidation只能在渲染()期間調用;

這裏是我的代碼

 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() 

感謝

+0

你打電話給這個事件? – cjk 2009-04-27 08:48:56

回答

1

您可以在web.config文件中這樣做,但在這種情況下,eventValidation將關閉所有的網頁。

,或者你可以在Page指令將關閉驗證單個頁面做到這一點。