c# - 扩展器控件 'HtmlEditorExtender1' 不是注册的扩展器控件

标签 c# asp.net webforms itextsharp ajaxcontroltoolkit

我有一个网络表单,我在上面使用了 ajax 工具包的 HtmlEditorExtender1。它工作正常。现在我正在尝试使用 iTextSharp 单击按钮将整个 webform 转换为 pdf。但是我收到了这个错误:

Extender control 'HtmlEditorExtender1' is not a registered extender control. Extender controls must be registered using RegisterExtenderControl() before calling RegisterScriptDescriptors().
Parameter name: extenderControl

我相信它与 HtmlEditorExtender1

有关
 <ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="txtkeyresultforyear" EnableSanitization="false" />

我的网络表单顶部如下所示:

<%@ Page Title="" Language="C#" MasterPageFile="~/ModuleMain.master" AutoEventWireup="true"
    ValidateRequest="false" CodeBehind="xyz.aspx.cs" EnableEventValidation = "false" Inherits="abc.xyz" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

这是我的按钮点击代码:

protected void btntopdf_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);

enter image description here

最佳答案

如果你的pdf是正确生成的

然后试试这段代码

        pdfWriter.CloseStream = false;
        pdfDoc.Close();
        HttpContext.Current.Response.Buffer = true;
        HttpContext.Current.Response.ContentType = "application/pdf";
        HttpContext.Current.Response.AddHeader("content-disposition:", "attachment;filename=" + _fileName + ".pdf");
        //  HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpContext.Current.Response.Write(pdfDoc);

保存为 pdf。

关于c# - 扩展器控件 'HtmlEditorExtender1' 不是注册的扩展器控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36687839/

相关文章:

javascript - 如何使用Java脚本刷新 GridView 内的标签?

c# - 使用表单例份验证返回登录屏幕

c# - 当 "externalizing"某些配置设置进入外部文件时行为不同

c# - 为什么我的控制台应用程序有命令历史记录?

c# - 如何使用查询语法来创建排列?

c# - 如何进行 ASP.NET 依赖注入(inject)

c# - Web 表单中的 ASP.Net 图表适用于本地系统,不适用于 Web 服务器

c# - 有没有办法使用正则表达式来分割 I[1,2]?

c# - 将应用程序缓存与 session 数据相结合时的信任边界违规

asp.net - 使用从独立 html 页面返回 json 的 asp.net web 服务