Click here to Skip to main content
13,048,035 members (111,627 online)
Rate this:
Please Sign up or sign in to vote.
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 9:07am
ThePhantomUpvoter 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 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 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 6 Jul 2013
Copyright © CodeProject, 1999-2017
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