0

我正在使用 iText dll 将 html 导出为 pdf。一个 asp 按钮用于 exporting.pdf 正在生成,但按钮单击事件自动调用 3 次。这是代码

protected void Button1_Click(object sender, EventArgs e)
{
    Response.ContentType = "application/pdf";

    Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");

    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    StringWriter sw = new StringWriter();

    HtmlTextWriter hw = new HtmlTextWriter(sw);

    gvDetails.RenderControl(hw);

    StringReader sr = new StringReader(sw.ToString());

    iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(PageSize.A4, 10f, 10f, 100f,0.0f);

    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

    pdfDoc.Open();

    htmlparser.Parse(sr);

    pdfDoc.Close();

    Response.Write(pdfDoc);

    Response.End();
}
4

1 回答 1

0

我会检查连接事件处理程序的代码。看起来好像连接了多次,导致方法被多次调用

于 2013-06-25T04:00:40.360 回答