Click here to Skip to main content
Rate this: bad
good
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");
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 6-Jul-13 10:07am
Comments
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 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 6 Jul 2013
Copyright © CodeProject, 1999-2014
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