Asp.net 将gridview导出到word

Asp.net 将gridview导出到word,asp.net,gridview,ms-word,Asp.net,Gridview,Ms Word,这是我在.cs文件中的代码,我正在尝试将gridview导出到word文件 但是当我运行代码时,它给出了一个错误 只能在Render()期间调用RegisterForEventValidation 请帮助从评论中复制答案: 获得答案guysEnableEventValidation=“false”只需将其添加到页面指令中即可获得答案guys EnableEventValidation=“false”只需将其添加到页面指令中即可 protected void Button2_Click(

这是我在.cs文件中的代码,我正在尝试将gridview导出到word文件 但是当我运行代码时,它给出了一个错误

只能在Render()期间调用RegisterForEventValidation
请帮助

从评论中复制答案:


获得答案guys
EnableEventValidation=“false”
只需将其添加到页面指令中即可

获得答案guys EnableEventValidation=“false”只需将其添加到页面指令中即可
     protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition",
            "attachment;filename=GridViewExport.doc");
            Response.Charset = "";
            Response.ContentType = "application/vnd.ms-word ";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.AllowPaging = false;
            GridView1.RenderControl(hw);
            Response.Output.Write(sw.ToString());
            Response.Flush();
            Response.End();
        }
        public override void VerifyRenderingInServerForm(Control control)
        {
            /* Verifies that the control is rendered */
        }