我的网络表单上有一个面板,在这个面板中我有很多东西和
按钮点击
protected void btntopdf_Click(object sender, EventArgs e)
{
AjaxControlToolkit.HtmlEditorExtender extender = (AjaxControlToolkit.HtmlEditorExtender)Panel1.FindControl("HtmlEditorExtender1");
Panel1.Controls.Remove(extender);
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);
Panel1.RenderControl(hw); // error over here
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();
}
错误:
Control 'ContentPlaceHolder1_ContentPlaceHolder1_HtmlEditorExtender1' of
type 'HtmlEditorExtender' must be placed inside a form tag with runat=server.
网络表单:
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Panel ID="Panel1" runat="server">
//lot of stuff in between
<ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="txtkeyresultforyear"
EnableSanitization="false">
</ajaxToolkit:HtmlEditorExtender>
//lot of stuff in between
</asp:Panel>
</asp:Content>
答案 0 :(得分:0)
然后,您需要在任何嵌套的母版页或内容页面上使用ScriptManagerProxy
。
当已在父元素中定义ScriptManager控件时,ScriptManagerProxy类允许嵌套组件(如内容页面和用户控件)向页面添加脚本和服务引用。
https://msdn.microsoft.com/en-us/library/cc295370.aspx
检查此link以获取ScriptmanagerProxy类引用
<强>更新强>
除此之外,您还需要覆盖VerifyRenderingInServerForm
https://msdn.microsoft.com/en-us/library/system.web.ui.page.verifyrenderinginserverform.aspx