aspx.cs中的代码
protected void btnExport_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
,并且显示错误 this.Page.RenderControl(hw);
显示错误,例如 只能在Render()期间调用RegisterForEventValidation;
我正在寻找解决方案- <%@页面语言=“ C#” AutoEventWireup =“ true” EnableEventValidation =“ false”>
但尚未解决。
我的页面中有 **
<script type="text/javascript">
var contnm = "<%= ContentPlaceHolder1.ClientID%>" + "_";
</script>
**
这可能就是为什么它显示错误。