Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
thia is my code

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);

p.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();

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
thaks
Posted
Comments
[no name] 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.
[no name] 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900