HTML解析器不会在当前上下文中退出 [英] HTML Parser does not exits in current context
本文介绍了HTML解析器不会在当前上下文中退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,伙计们,当我运行我的网站时,它提示错误HTML Parser在当前上下文中不存在,可以告诉我我在哪里做错了,我的代码是这个..
Hello, guys, when i run my website, then it give the error HTML Parser does not exits in current context, can any tell me where i am doing mistake, my code is this..
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.IO;
using System.Xml;
using iTextSharp.text.html;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using CityBusinessLogics;
private void Page_Load(object sender, System.EventArgs e)
{
lblregno.Text = Request.QueryString["Parameter"].ToString();
pdfgenrate();
// barcode();
//print();
}
public void pdfgenrate()
{
Mypage tmpPage = new Mypage();
HtmlForm form = new HtmlForm();
form.Controls.Add(Panel1 );
tmpPage.Controls.Add(form);
StringWriter sw = new StringWriter();
HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
form.Controls[0].RenderControl(htmlWriter);
string htmlContent = sw.ToString();
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document, new FileStream("c:\\Chap0101.pdf", FileMode.Create));
// step 3: we open the document
document.Open();
// step 4: we add a paragraph to the document
//document.Add(new Paragraph(htmlContent.ToString()));
System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlContent));
HtmlParser.Parse(document, _xmlr);
// step 5: we close the document
document.Close();
ShowPdf("c:\\Chap0101.pdf");
}
private void ShowPdf(string s)
{
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "inline;filename=" + s);
Response.ContentType = "application/pdf";
Response.WriteFile(s);
Response.Flush();
Response.Clear();
}
public override void VerifyRenderingInServerForm(Control control)
{
Panel pan = control as Panel;
if (pan != null && pan.ID == "Panle1")
return;
else
base.VerifyRenderingInServerForm(control);
/* Verifies that the control is rendered */
}
private void ShowPdf(string s)
{
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "inline;filename=" + s);
Response.ContentType = "application/pdf";
Response.WriteFile(s);
Response.Flush();
Response.Clear();
}
public override void VerifyRenderingInServerForm(Control control)
{
Panel pan = control as Panel;
if (pan != null && pan.ID == "Panle1")
return;
else
base.VerifyRenderingInServerForm(control);
/* Verifies that the control is rendered */
}
请帮帮我.
在此先感谢
Please help me.
Thanks in advance
推荐答案
我不知道您是否从IDE复制或粘贴了代码,或者这是什么,但这看起来不正确;
I don''t know if you copied and pasted your code from your IDE or what, but this bit doesn''t look right;
form.Controls.Add(Panel1 );
tmpPage.Controls.Add(form);
在将Panel1添加到表单之前,先在哪里实例化它(然后将表单添加到页面中).在将元素添加到集合之前,您应该在一行上类似于表单和tmp页面创建的地方来创建元素,例如;
Where do you instantiate Panel1 before adding it to the form (and then add the form to the page). You should have a line somewhere similiar to your form and tmp page creation, to create the element before you add it to the collection, e.g.;
Panel Panel1 = new Panel();
这篇关于HTML解析器不会在当前上下文中退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文