Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET itextsharp
thia is my code
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

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);
P is Panel control.
Panel control in a page and the page has a master page.
I get this error
ontrol 'MainContent_txtEmail' of type 'TextBox' must be placed inside a form tag with runat=server.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Control 'MainContent_txtEmail' of type 'TextBox' must be placed inside a form tag with runat=server.
Source Error:

Line 96: HtmlTextWriter hw = new HtmlTextWriter(sw);
Line 97:
Line 98: p.RenderControl(hw);
Line 99: StringReader sr = new StringReader(sw.ToString());
Line 100: Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
please help me to solve this
Posted 6-Jul-13 10:07am
ThePhantomUpvoter at 6-Jul-13 15:23pm
Control 'MainContent_txtEmail' of type 'TextBox' must be placed inside a form tag with runat=server. Which part is unclear?
KuntalBose at 6-Jul-13 17:19pm
this is the error message i get at run time show in browser.
NOTE:If i run this same code a page without any master page its running fine,
but a page with master page,there i get this error.
ThePhantomUpvoter at 6-Jul-13 21:25pm
Yes I see that. The error message is perfectly clear and even goes so far as to tell you exactly what you need to do to fix it. So again, which part is it that you do not understand?
sewarts at 20-Nov-13 8:05am
The reason it is not clear is that the control IS inside a form tag with runat=server. To solve pass each control that errors through this method before rendering to pdf:
public override void VerifyRenderingInServerForm(Control control)
/* Verifies that the control is rendered */

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 580
1 OriginalGriff 420
2 Sascha Lefévre 289
3 Abhinav S 220
4 CHill60 200
0 Sergey Alexandrovich Kryukov 9,773
1 OriginalGriff 9,290
2 Peter Leow 5,137
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 3,036

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 6 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100