Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

render a control in page_load

Status
Not open for further replies.

organicg

Programmer
Oct 21, 2002
151
US
I'm using a PDF component that takes HTML and creates a PDF that I'm putting in the response as an attachment(which prompts 'open or save' dialog box. The HTML I need to pass to the PDF object is the main Panel control on the page(it has 3 child controls, too). The problem is that since I'm doing this in Page.Page_Load, the Panel.Load hasn't fired and doesn't contain the HTML yet. At least I think this is the problem, but not positive. I've tried calling Panel.RenderControl but that's still blank output. Any advice?

In the page_load...
Code:
System.IO.StringWriter stringWriter = new System.IO.StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
			
ReportLayoutMain.RenderControl(htmlTextWriter);
stringWriter = (System.IO.StringWriter)htmlTextWriter.InnerWriter;
			
thePDFDoc.AddImageHtml(stringWriter.ToString());
byte[] theData = thePDFDoc.GetData();

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=report.pdf");
Response.AddHeader("content-length", theData.Length.ToString()); 
Response.BinaryWrite(theData);
 
Ahh, the .PreRender event to the rescue. Basically, I just put the code above in a Page_PreRender method(and add the event delegate) and the HTML output automagically shows up!

Thanks myself
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top