Greetings again experts,
I got this awesome code from here - aspsnippets.com:
https://www.aspsnippets.com/Articles/Export-HTML-DIV-contents-to-PDF-using-iTextSharp-in-ASPNet.aspx
protected void btnExport_Click(object sender, EventArgs e)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlContents.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();
}
In the markup, I am using Multiview control with four views inside it.
Inside one of those views is panel control pnlContents.
I am trying to export contents inside this panel.
Inside this panel control is a checkbox with contol ID called chksameAddr. It has a runat="server" attribute.
All of these are inside a form tag also with a runat="server" attribute.
Code is very long but I mimmicked the code from aspsnippets.com.
The difference is the multiview control.
When I run the code, I get the following error:
Control 'chksameAddr' of type 'CheckBox' must be placed inside a form tag with runat=server.
The error is on this line:
pnlContents.RenderControl(hw);
Any idea how to resolve this?
Many thanks for the continued assistance.