Wrox Programmer Forums
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2007, 12:00 AM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default using Page.RenderControl()

I have a webpage which is displayed a series of times with different controls each time.

I have a function which has the code to generate the controls dynamically which is a called in the next button.

Now my requirement is that, whenever the user clicks the next button I have to capture the current page with the controls and the data in it (static) in the form of pdf file and finally at the last when the user clicks the submit button I have to merge the pdf files and pop it up .

To generate the pdf I am using a third party dll which needs html source of the page so to get that i am using the following code

protected void ExportToPDF()
{
try
{

System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
Page.RenderControl(oHtmlTextWriter);
oHtmlTextWriter.Flush();


string pageSoure = oStringWriter.ToString();
oHtmlTextWriter.Close();

PdfConverter pdfcon = new PdfConverter();
pdfcon.LicenseFilePath = Server.MapPath("Bin/");
pdfcon.PageWidth = 900;
pdfcon.PdfDocumentOptions.LeftMargin = 25;
pdfcon.PdfDocumentOptions.RightMargin = 25;
pdfcon.AvoidTextBreak = true;
pdfcon.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape;
pdfcon.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
pdfcon.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
pdfcon.SavePdfFromHtmlStringToFile(pageSoure, Request.PhysicalApplicationPath + @"\temp\" + pageID.ToString() + ".pdf");

pageSoure = "";

}
catch
{}
}

here I am using a third party dll to convert to pdf ....now wen i call this function in the next button I am getting an http error as "A page can have only one server-side Form tag."

Please help me regarding this .

Thanks in advance

 
Old June 8th, 2011, 02:06 AM
Registered User
 
Join Date: Jun 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi, i have the same problem. The only difference is that i started by a sample program from here:http://www.voip-sip-sdk.com/p_159-ho...urce-voip.html


Maybe you can find the mistake here - i couldn't
 
Old May 26th, 2014, 04:26 AM
Registered User
 
Join Date: Dec 2013
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default RE: using Page.RenderControl()

Hi, try overriding the VerifyRenderingInServerForm method, like the following:
Code:
public override void VerifyRenderingInServerForm(Control control)
{ }
That worked for me and I hope it will help anyone that encounters this issue. Also I used a different third party component, this Word DLL written in C#, here is how you can try it out:
Code:
protected void ExportToPDF()
{
	System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
	System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
	Page.RenderControl(oHtmlTextWriter);
	string pageSoure = oStringWriter.ToString();

	DocumentModel document;
	HtmlLoadOptions option = new HtmlLoadOptions() { BaseAddress = this.Request.PhysicalApplicationPath };
	using (Stream htmlStream = new System.IO.MemoryStream(option.Encoding.GetBytes(pageSoure)))
		document = DocumentModel.Load(htmlStream, option);

	PageSetup page = document.Sections[0].PageSetup;
	page.PageWidth = 900;
	page.PageMargins.Left = 25;
	page.PageMargins.Right = 25;
	page.Orientation = Orientation.Landscape;
	page.PaperType = PaperType.A4;
	
	document.Save(Request.PhysicalApplicationPath + @"\temp\" + pageID.ToString() + ".pdf");
}
In one of my previous project I used it to convert HTML files (from various sources) into PDF files through C#. Also before showing them I needed to join these multiple files (this can also be easily done in this DLL with import method) and then export the generated PDF to an ASP.NET client.





Similar Threads
Thread Thread Starter Forum Replies Last Post
access C#.Net page as action of calssic ASP page mansharma_s ASP.NET 1.x and 2.0 Application Design 6 January 7th, 2008 10:58 AM
RenderControl and Render methods joxa83 ASP.NET 1.x and 2.0 Application Design 4 August 24th, 2006 08:10 AM
Using rendercontrol with parameters? shenku C# 2 October 13th, 2005 09:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.